<?
//impostazioni modulo Prodotti - Servizi
include("includes/config.inc.php");
include("includes/auth.lib.php");
include("includes/function.inc.php");
include("includes/product_new.class.php");
include("includes/e-commerce_new.class.php");
include("includes/newsletter.class.php");
include("includes/image.class.php");
include("includes/upload.class.php");
// include Editor Start
include("FCKeditor2.4.3/fckeditor.php");
// include Editor Ende
$module = "PRODOTTI";
switch($lang) {
	case "ita":
		$currentlang = " - ITA";
		break;

	case "eng":
		$currentlang = " - ENG";
		break;

	case "fra":
		$currentlang = " - FRA";
		break;

	case "esp":
		$currentlang = " - ESP";
		break;
}
$javascript = "function control_addcat()  {
					if(document.formaddcat.titolo.value == '')  {
					 alert('Attenzione! Devi inserire almeno il titolo.');
					 return false;
					}   else
					 return true;
}

				function control_cat()  {
					if(document.formeditcat.titolo.value == '')  {
					 alert('Attenzione! Devi inserire almeno il titolo.');
					 return false;
					}   else
					 return true;
}

				function control_sottocat()  {
					if(document.formaddsottocat.titolo.value == '')  {
					 alert('Attenzione! Devi inserire almeno il titolo.');
					 return false;
					}   else
					 return true;
}

				function control_categoria()  {
					if(document.addcategoria.titolo.value == '')  {
					 alert('Attenzione! Devi inserire almeno il titolo.');
					 return false;
					}   else
					 return true;
}

				function control_articolo()  {
					if(document.formarticolo.titolo1.value == '')  {
					 alert('Attenzione! Devi inserire almeno il titolo.');
					 return false;
					}   else
					 return true;
}
";
list($status, $user) = auth_get_status();
switch($status){
	case AUTH_LOGGED:
		$result1 = @mysql_query("SELECT nome,stato FROM utenti WHERE id='$id_user';");
		list($username,$level) = mysql_fetch_row($result1);
		//recupero i dati in post
		$currentpage = urldecode($_POST['currentpage']);
		if($currentpage == "")
		$currentpage = urldecode($_GET['currentpage']);
		if($currentpage == "")  {
			$currentpage = $_SERVER['REQUEST_URI'];
			$start = strlen($_SERVER['SCRIPT_NAME']) - 15;
			$url = substr($currentpage, $start);
			//die($currentpage."<br>".$start."<br>".$url);
			$currentpage = urlencode($url);
		}
		$percorso = $_GET['percorso'];
		if($percorso == "")  {
			$percorso = $_POST['percorso'];
		} else
		$percorso = urldecode($percorso);
		$last_folder = "/".substr(strrchr($percorso, "/"), 1);
		$percorso_prec = str_replace($last_folder, "", $percorso);
		$op = $_GET['op'];
		if(!isset($op) || $op == "")
		$op = $_POST['op'];
		$op_var = $_GET['op_var'];
		if(!isset($op_var) || $op_var == "")
		$op_var = $_POST['op_var'];
		//categorie
		$cids = $_GET['cid'];
		if(!isset($cids) || $cids == "")
		$cids = $_POST['cid'];
		$titolos = $_POST['titolo'];
		$desc = $_POST['desc'];
		$idfather = $_POST['idfather'];
		//#####################################
		$ordines = $_POST['ordine'];
		//prodotti
		$idarticolos = $_GET['idarticolo'];
		if(!isset($idarticolos) || $idarticolos == "")
		$idarticolos = $_POST['idarticolo'];
		$codice = $_POST['codice'];
		$titolo1 = $_POST['titolo1'];
		$titolo2 = $_POST['titolo2'];
		$desc = $_POST['desc'];
		$image_tmb = $_FILES['image_tmb'];
		$image = $_FILES['image'];
		$image_big = $_FILES['image_big'];
		$video = $_FILES['video'];
		$prezzo1 = $_POST['prezzo1'];
		$prezzo2 = $_POST['prezzo2'];
		$spedizione = $_POST['spedizione'];
		$spedizione2 = $_POST['spedizione2'];
		$promozione = $_POST['promozione'];
		$vetrina = $_POST['vetrina'];
		$novita = $_POST['novita'];
		$minimo = $_POST['minimo'];
		$peso = $_POST['peso'];
		$scheda = $_POST['scheda'];
		$disp = $_POST['disp'];
		$banner = $_POST['banner'];
		$fornitore = $_POST['fornitore'];
		$fornitore_add = $_POST['fornitore_add'];
		if($fornitore_add!="") $fornitore = $fornitore_add;
		$produttore = $_POST['produttore'];
		$produttore_add = $_POST['produttore_add'];
		if($produttore_add!="") $produttore = $produttore_add;
		$costo = $_POST['costo'];
		$varianti = $_POST['varianti'];
		$misura = $_POST['misura'];
		$note = $_POST['note_admin'];
		$multiplo = $_POST['multiplo'];
		####################################################################################################
		$tagtitles = $_POST['tagtitle'];
		$tagkeys = $_POST['tagkey'];
		$metatitles = $_POST['metatitle'];
		$metakeys = $_POST['metakey'];
		$metadescs = $_POST['metadesc'];
		$hiddens = $_POST['hidden'];
		$tagdescs = $_POST['tagdesc'];
		####################################################################################################
		if($level!="VBL")  {
			$menusx = "<table width=203 cellpadding=3 border=0><tr><td class=menusx colspan=6><b>Categorie</b></td></tr>\n";
			$rmax = $conn->Execute("SELECT MAX(ordine) as maxordine FROM categorie WHERE lang='$lang' AND idfather='0';");
			$maxordine = $rmax->Fields("maxordine");
			$rmax->Close();
			$qry_topic = "SELECT cid,titolo,ordine,attivo FROM categorie WHERE lang='$lang' AND idfather='0' AND cid=733 ORDER BY ordine;";
			$rt = $conn->Execute($qry_topic);
			$num_topic = $rt->RecordCount();
			if($num_topic > 0)  {
				while(!$rt->EOF)  {
					$cid = $rt->Fields("cid");
					$titolo = $rt->Fields("titolo");
					$ordine = $rt->Fields("ordine");
					$attivo = $rt->Fields("attivo");
					if($ordine == "0")
					$up = "&nbsp;";
					else
					$up = "<a href=product_new.php?op=up&cid=$cid&currentpage=$currentpage&percorso=".urlencode($percorso)."><img src=imgs/ico_up.gif width=16 height=16 alt=\"sposta su\" border=0></a>";
					if($ordine == $maxordine)
					$down = "&nbsp;";
					else
					$down = "<a href=product_new.php?op=down&cid=$cid&currentpage=$currentpage&percorso=".urlencode($percorso)."><img src=imgs/ico_down.gif width=16 height=16 alt=\"sposta gi&ugrave;\" border=0></a>";
					#########################################################################################
					if($attivo == "y")
					$semaforo = "<a href=\"product_new.php?op=disactivecat&cid=$cid&currentpage=$currentpage&percorso=".urlencode($percorso)."\"><img src=\"imgs/ico_green.jpg\" border=0 alt=Disattiva></a>";
					else
					$semaforo = "<a href=\"product_new.php?op=activecat&cid=$cid&currentpage=$currentpage&percorso=".urlencode($percorso)."\"><img src=\"imgs/ico_red.jpg\" border=0 alt=Attiva></a>";
					#########################################################################################
					$menusx .= "<tr>
					  <td class=menusx><a class=menusx href=\"product_new.php?cid=$cid&op=product&percorso=/".$titolo."\">$titolo</a></td>
					   <td class=menusx>$up</td>
					   <td class=menusx>$down</td>				  
					  <td><a href=\"product_new.php?op=del&cid=$cid&currentpage=$currentpage\" onclick=\"return confirm('Sei sicuro di voler eliminare la categoria ?');\"><img src=imgs/ico_delete.gif width=16 height=16 alt=\"elimina\" border=0></a></td>
					  <td>$semaforo</td>
					  </tr>\n";
					$rt->MoveNext();
				}
				$rt->Close();
				$menusx .= "<tr><td colspan=6 class=menusx bgcolor=\"#CCCCCC\"><a class=menusx href=javascript:; onclick=\"showHide('addcategoria2','','');\">Aggiungi categoria principale</a></td></tr></table>";
			} else {
				$menusx = '<table width="22" cellpadding="0" cellspacing="0">
				<tr>
				 <td width="22">
				  <a href="../gestione.php?module=change_lang&newlang=eng"><img src="../imgs/icons/ico-eng.jpg" alt="Inglese" width="20" height="20" border="0"></a></td>
				</tr>
				<tr>
				<td class="error" width="22" align="center" valign="middle"><a href="../gestione.php?module=change_lang&newlang=ita"><img src="../imgs/icons/ico-ita.jpg" alt="Italiano" width="20" height="20" border="0"></a></td>
				</tr>
			   </table>';
			}
			$content = "&nbsp;";
		}
		//######################opzioni possibili############################################
		//die("op: $op");
		if($op=="" && $op_var!="") $op = $op_var;
		switch ($op)  {
				
			case "product":
				$currentCat = new category($cids);
				$navbar = category::getNavbarAdmin($cids," ".$currentCat->titolo);
				####################### indicizzazione ##############################################################
		  $tagtitle = $currentCat->tagtitle;
		  $tagkey = $currentCat->tagkey;
		  $tagdesc = $currentCat->tagdesc;
		  $metatitle = $currentCat->metatitle;
		  $metakey = $currentCat->metakey;
		  $metadesc = $currentCat->metadesc;
		  $hidden = $currentCat->hidden;
		  ####################################################################################################
		  $content = "<table class=\"content\" width=\"100%\" align=\"left\" cellpadding=\"3\" cellspacing=\"0\" border=0>
					<tr>
					 <td colspan=2 class=tbtit>Navbar :: $navbar</td>
					</tr>";
		  //elenco sottocategorie
		  $content .= "<tr>
				   				<td colspan=2 valign=top>".$currentCat->listCat($percorso)."</td>
				 			  </tr>";	
		  //pulsante modifica dati categoria
		  $content .= "<tr>
				 		<td colspan=2><a href=\"javascript:showHide('editCat','','');\">MODIFICA DATI CATEGORIA</a><br>
						<table id='editCat' width=700 cellpadding=3 border=0 class=content bgcolor=#CCCCCC>
						 <tr>
						 	<td colspan=2 class=error align=center>DATI CATEGORIA</td>
						 </tr>
						 <form name=formeditcat action=product_new.php method=POST>
						 <tr>
						  <td width=100 align=right>Titolo:</td>
						  <td width=600><input type=text size=100 name=titolo value=\"$currentCat->titolo\"></td>
						 </tr>
						 <tr> 
						  <td colspan=2 valign=top>Descrizione categoria:<br>";
				//start editor
				$oFCKeditor = new FCKeditor('desc_update');
				$oFCKeditor->Value = "$currentCat->desc";
				$content .= $oFCKeditor->Create();
				$content .= "</td>
						 </tr>
						 <tr>
		 <td colspan=2 valign=top>
		 <table width=550 class=content border=0 cellpadding=2>
		   <tr>
		    <td width=100 align=right valign=top>Permalink:</td>
			<td valign=top><input type=text name=hidden size=50 value=\"$hidden\"></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Titolo pagina:<br>Tag &lt;title&gt;</td>
			<td valign=top><textarea name=tagtitle rows=5 cols=100>$tagtitle</textarea></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Parole chiave:<br>Meta-tag &lt;keywords&gt;</td>
			<td valign=top><textarea name=tagkey rows=5 cols=100>$tagkey</textarea></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Descrizione pagina:<br>Meta-tag &lt;description&gt;</td>
			<td valign=top><textarea name=tagdesc rows=5 cols=100>$tagdesc</textarea></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Titolo documento:<br>Meta-tag &lt;title&gt;</td>
			<td valign=top><textarea name=metatitle rows=5 cols=100>$metatitle</textarea></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Frasi documento:<br>Meta-tag &lt;Keyphrase&gt;</td>
			<td valign=top><textarea name=metakey rows=5 cols=100>$metakey</textarea></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Descrizione:<br>Meta-tag &lt;http-equiv=\"description\"&gt;</td>
			<td valign=top><textarea name=metadesc rows=5 cols=100>$metadesc</textarea></td>
		   </tr>
		 </table>
	   </td>
	  </tr>
						 <tr>
						  <td colspan=2 align=center>		 
						  <input type=hidden name=cid value=\"$cids\">
						  <input type=hidden name=currentpage value=\"$currentpage\">
						  <input type=hidden name=op value=update>
		 <input type=image src=\"imgs/ico_save.gif\" title=Salva onClick=\"return control_cat();\" width=16 height=16>&nbsp;&nbsp;<a class=content href=\"javascript:document.formeditcat.submit();\" onClick=\"return control_cat();\">Salva modifiche</a></td>
						 </tr>
						  </form>
						</table>
						</td>
				 </tr>";
				//pulsante aggiungi categoria
				$content .= "<tr>
				 		<td colspan=2><a href=\"javascript:showHide('addCat','','');\">AGGIUNGI SOTTOCATEGORIA</a><br><br>
						<table id='addCat' width=700 cellpadding=3 border=0 class=content bgcolor=#CCCCCC style=\"visibility:hidden; display:none;\">
						 <form name=formaddsottocat action=product_new.php method=POST>
						 <tr>
						  <td width=100 align=right>Titolo:</td>
						  <td width=600><input type=text size=100 name=titolo></td>
						 </tr>
						 <tr> 
						  <td colspan=2 valign=top>Descrizione categoria:<br>";
				//start editor
				$oFCKeditor = new FCKeditor('desc');
				$content .= $oFCKeditor->Create();
				$content .= "</td>
						 </tr>
						 <tr>
						  <td colspan=2 align=center>		 
						  <input type=hidden name=idfather value=\"$cids\">
						  <input type=hidden name=currentpage value=\"$currentpage\">
						  <input type=hidden name=op value=save>
		 <input type=image src=\"imgs/ico_save.gif\" title=Salva onClick=\"return control_sottocat();\" width=16 height=16>&nbsp;&nbsp;<a class=content href=\"javascript:document.formaddsottocat.submit();\" onClick=\"return control_sottocat();\">Salva sottocategoria</a></td>
						 </tr>
						  </form>
						</table>
						</td>
				 </tr>
				 <tr>
				  <td colspan=2 style=\"border-bottom:1px solid #3B88C2\"><img src=imgs/spacer.gif height=20></td>
				 </tr>
				 <tr>
				  <td colspan=2>
				    <form action=\"product_new.php\" method=POST>
				    	Correlare di blocco gli articoli all'interno di questa categoria con: ";
				$sql = "SELECT titolo,cid FROM categorie WHERE attivo='y' AND lang='ita' ORDER BY titolo ASC;";
				$rs_menu = $conn->Execute($sql);
				$content .= $rs_menu->GetMenu("cid_corr","",false);
				$content .=	"<input type=\"hidden\" name=\"op\" value=\"correla_gruppo\">
				    	<input type=\"hidden\" name=\"cid_from\" value=\"$cids\">
				    	&nbsp;<input type=\"submit\" value=\"CORRELA\">
				    </form>
				  </td>
				 </tr>
				 <tr>
				  <td colspan=2 style=\"border-top:1px solid #3B88C2\"><img src=imgs/spacer.gif height=20></td>
				 </tr>";
				$content .= "<tr>
				  				<td colspan=2>".$currentCat->listProd($currentpage)."</td>
				 			  </tr>\n";
				//spazio
				//$content .= "<tr><td colspan=2>&nbsp;</td></tr>\n";
				if(isset($idarticolos) && $idarticolos != "") {
					//pagina di modifica prodotto
					$newArt = new articoli($idarticolos);
					####################### indicizzazione ##############################################################
					$tagtitle = $newArt->tagtitle;
					$tagkey = $newArt->tagkey;
					$tagdesc = $newArt->tagdesc;
					$metatitle = $newArt->metatitle;
					$metakey = $newArt->metakey;
					$metadesc = $newArt->metadesc;
					$hidden = $newArt->hidden;
					$cat_cid = $newArt->cid;
					####################################################################################################
					$hidden_id = "<input type=hidden name=\"idarticolo\" value=\"$idarticolos\"><input type=hidden name='op' value='update_art'>
		  <input type=hidden name=currentpage value=\"product_new.php?idarticolo=$idarticolos&op=product\">";
					$button = "- <a href=\"javascript:document.formarticolo.reset();\"><img src=\"imgs/reset.gif\" width=16 height=16 border=0 alt=\"Reimposta\">&nbsp;&nbsp;Annulla modifiche</a>";
					if($newArt->image != "")  {
						if($newArt->import == "1") {
							if(file_exists($_SERVER['DOCUMENT_ROOT']."/immagini-mrpiscina/".$newArt->image))
							$src_image = "<img src=\"/immagini-mrpiscina/$newArt->image\">";
						} else
						$src_image = "<img src=\"imgs_prodotti/$idarticolos/$newArt->image\" width=".IMAGE_W." height=".IMAGE_H.">";
					}
					if($newArt->image_big != "") {
						if($newArt->import == "1") {
							if(file_exists($_SERVER['DOCUMENT_ROOT']."/immagini-mrpiscina/".$newArt->image_big))
							$src_image_big = "<img src=\"/immagini-mrpiscina/$newArt->image_big\">";
						} else
						$src_image_big = "<img src=\"imgs_prodotti/$idarticolos/$newArt->image_big\" width=".IMAGE_W." height=".IMAGE_H.">";
					}
					if($newArt->import == "0") {
						$code_images .= "<tr>
			 <!--<td widht=50% align=center valign=top><b>Immagine piccola 80 X 80 px</b><br><br><input type=file name=image size=50><br><br>$src_image</td>-->
			 <td widht=50% align=center valign=top><b>Immagine da ridimensionare (DEVE ESSERE QUADRATA)</b><br><input type=file name=image_big size=50><br><br>$src_image_big</td>
			</tr>";
					} else {
						$code_images .= "<tr>
			 <td widht=50% align=center valign=top><br><br>$src_image</td>
			 <td widht=50% align=center valign=top><b>Immagine media larghezza Max. 600 px</b><br><input type=file name=image_big size=50><br><br>$src_image_big</td>
			</tr>";
					}
					################################# VIDEO #####################################################
					if($newArt->video != "") {
						list($id,$nome_video) = explode("/",$newArt->video);
						if(lang == "ita" || $nome_video == "")
						$src_video = "<a href=\"javascript:;\" onClick=\"javascript:window.open('show_video.php?video=$idarticolos/$newArt->video')\">Guarda il video</a>";
						else
						$src_video = "<a href=\"javascript:;\" onClick=\"javascript:window.open('show_video.php?video=$newArt->video')\">Guarda il video</a>";
					}
					############################################################################################
					$onload = "showHide('addarticolo');document.formarticolo.titolo1.focus();";
				}  else  {
		 		//tasto aggiungi prodotto
		 			$cat_cid = $cids;
					$content .= "<tr><td class=content colspan=2><a class=content href=javascript:; onclick=\"showHide('addarticolo');\">AGGIUNGI ARTICOLO</a></td></tr>";
		  	$hidden_id = "<input type='hidden' name='op' value='save_art'><input type=\"hidden\" name=\"currentpage\" value=\"$currentpage\">";
		  	$code_images .= "<tr>
			 <td widht=50% align=center valign=top><!--<b>Immagine piccola 80 X 80 px</b><br><input type=file name=image size=50>--><br><br>$src_image</td>
			 <td widht=50% align=center valign=top><b>Immagine da ridimensionare (DEVE ESSERE QUADRATA)</b><br><input type=file name=image_big size=50><br><br>$src_image_big</td>
			</tr>";
				}
		  if($newArt->promozione == "y")
		  $prom_si = "checked";
		  else
		  $prom_no = "checked";
		  if($newArt->vetrina == "y")
		  $vet_si = "checked";
		  else
		  $vet_no = "checked";
		  if($newArt->novita == "y")
		  $nov_si = "checked";
		  else
		  $nov_no = "checked";
		  $ricerca = Variante::getCampiRicerca($newArt,$currentCat->idfather);
		  $content .="<tr><td colspan=2 class=\"content\"><div id=\"addarticolo\">
		<table width=700px cellpadding=2 cellspacing=0 style=\"border:2px solid #EFEFEF;\" class=content bgcolor=#CCCCCC border=0>";
		  $content .= "<form name=formarticolo action=product_new.php method=post enctype=\"multipart/form-data\">
<tr>
		  <td width=175 align=right>Categoria:</td><td width=175>";
		  
		  $sql = "SELECT titolo,cid FROM categorie WHERE lang='$lang' ORDER BY titolo ASC;";
		  $rs_menu = $conn->Execute($sql);
		  $content .= $rs_menu->GetMenu2("cid",$cat_cid,false);
		  $rs_menu->Close();
		  $content .= "</td><td width=175 align=right>Codice:</td><td width=175><input type=text name=codice size=10 value=\"$newArt->codice\"></td>
		 </tr>
		 <tr>
		  <td align=right>Titolo:</td><td><input type=text name=titolo1 size=80 value=\"$newArt->titolo1\"></td>
		  <td align=right>Sottotitolo:</td><td><input type=text name=titolo2 size=30 value=\"$newArt->titolo2\"></td>
		 </tr>
		 <tr>
		  <td colspan=4>Descrizione articolo:<br>
		   <textarea name=desc cols=130 rows=5>".str_replace("<br>","\r",$newArt->desc)."</textarea>
			</td>
		 </tr>
		 <tr>
		  <td colspan=4 align=center>
		   <table width=100% cellpadding=2 border=0 class=content>
		    <tr>
			 <td colspan=2 class=error align=center>Gestione immagini</td>
			</tr>$hiddenImages
			$code_images
			<tr>
			  <td colspan=2 class=error align=center>Gestione Video</td>
			</tr>
			<tr>
			 <td colspan=2 align=center>$src_video<br><br>
			  Inserisci video:&nbsp;<input type=file name=video size=50>
			 </td>
			</tr>
			<tr>
			 <td colspan=2 align=center valign=top>";
			//start editor
			$oFCKeditor = new FCKeditor('scheda');
			if($newArt->scheda!="")
			$oFCKeditor->Value = "$newArt->scheda";
			else
			$oFCKeditor->Value = '<table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="20"><img src="http://www.bsvillage.com/images/spacer.gif" width="20" height="36"></td>
                      <td width="670" valign="top" class="plain"><table width="670" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td><img src="http://www.bsvillage.com/images/spacer.gif" width="670" height="10"></td>
                        </tr>
                      </table>
                        <table width="670" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td><img src="http://www.bsvillage.com/images/boxProdTop.gif" width="670" height="18"></td>
                        </tr>
                        <tr>
                          <td background="http://www.bsvillage.com/images/boxProdCnt.gif"><table width="670" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="20"><img src="http://www.bsvillage.com/images/spacer.gif" height="20" width="20"></td>
                              <td width="630">&nbsp;</td>
                              <td width="20"><img src="http://www.bsvillage.com/images/spacer.gif" height="20" width="20"></td>
                            </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td><img src="http://www.bsvillage.com/images/boxProdBtm.gif" width="670" height="18"></td>
                        </tr>
                      </table>
                        <table width="670" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td><img src="http://www.bsvillage.com/images/spacer.gif" width="670" height="10"></td>
                          </tr>
                        </table>
                        <table width="670" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td><img src="http://www.bsvillage.com/images/boxProdTop.gif" width="670" height="18"></td>
                          </tr>
                          <tr>
                            <td background="http://www.bsvillage.com/images/boxProdCnt.gif"><table width="670" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="20"><img src="http://www.bsvillage.com/images/spacer.gif" height="20" width="20"></td>
                              <td width="630">&nbsp;</td>
                              <td width="20"><img src="http://www.bsvillage.com/images/spacer.gif" height="20" width="20"></td>
                            </tr>
                          </table></td>
                          </tr>
                          <tr>
                            <td><img src="http://www.bsvillage.com/images/boxProdBtm.gif" width="670" height="18"></td>
                          </tr>
                        </table>
                        <table width="670" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td><img src="http://www.bsvillage.com/images/spacer.gif" width="670" height="10"></td>
                          </tr>
                        </table>
                        <table width="670" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td><img src="http://www.bsvillage.com/images/boxProdTop.gif" width="670" height="18"></td>
                          </tr>
                          <tr>
                            <td background="http://www.bsvillage.com/images/boxProdCnt.gif"><table width="670" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="20"><img src="http://www.bsvillage.com/images/spacer.gif" height="20" width="20"></td>
                              <td width="630">&nbsp;</td>
                              <td width="20"><img src="http://www.bsvillage.com/images/spacer.gif" height="20" width="20"></td>
                            </tr>
                          </table></td>
                          </tr>
                          <tr>
                            <td><img src="http://www.bsvillage.com/images/boxProdBtm.gif" width="670" height="18"></td>
                          </tr>
                        </table></td>
                      <td width="20"><img src="http://www.bsvillage.com/images/spacer.gif" width="20" height="36"></td>
                    </tr>
                  </table>';  
			$content .= $oFCKeditor->Create();
			$content .= "</td>
			</tr>
		   </table>
		  </td>
		 </tr>
		 <tr>
		  <td align=right>Prezzo:</td><td><input type=text name=prezzo1 size=10 value=\"$newArt->prezzo1\">&nbsp;&euro;</td>
		  <td align=right>Prezzo scontato:</td><td><input type=text name=prezzo2 size=10 value=\"$newArt->prezzo2\">&nbsp;&euro;</td>
		 </tr>
		 <tr>
		   <td align=right>Prezzo Riv.:</td><td><input type=text name=costo size=10 value=\"$newArt->costo\">&nbsp;&euro;</td>
		 </tr>
		 <tr>
		  <td align=right>Spese di spedizione:</td><td><input type=text name=spedizione size=10 value=\"$newArt->spedizione\">&nbsp;&euro;</td>
		  <td align=right>Dopo il secondo prodotto:</td><td><input type=text name=spedizione2 size=10 value=\"$newArt->spedizione2\">&nbsp;&euro;</td>
		  </tr>
		  <tr>
		  <td align=right>Metti in promozione:</td><td><input type=radio style=\"background-color:#CCCCCC\" name=promozione value=y $prom_si>&nbsp;si&nbsp;&nbsp;<input type=radio style=\"background-color:#CCCCCC\" name=promozione value=n $prom_no>&nbsp;no</td>
		  <td align=right>Novita:</td><td><input type=radio style=\"background-color:#CCCCCC\" name=novita value=y $nov_si>&nbsp;si&nbsp;&nbsp;<input type=radio style=\"background-color:#CCCCCC\" name=novita value=n $nov_no>&nbsp;no</td>
		  <tr>
		  <td align=right>Metti in vetrina:</td><td><input type=radio style=\"background-color:#CCCCCC\" name=vetrina value=y $vet_si>&nbsp;si&nbsp;&nbsp;<input type=radio style=\"background-color:#CCCCCC\" name=vetrina value=n $vet_no>&nbsp;no</td>
		  <td align=right>Ordine minimo:</td><td><input type=text name=minimo size=10 value=\"$newArt->minimo\"></td>
		 </tr>
		 <tr> 
		   <td align=right>Quantit&agrave; multipla:</td><td><input type=text name=multiplo size=10 value=\"$newArt->multiplo\"></td>
		 </tr>
		 <tr> 
		  <td align=right>Disponibilit&agrave;:</td>
		  <td>
		  <select name=\"disp\">
		    <option value=\"1\""; if($newArt->disp=="1") $content.=" selected"; $content.=">Disponibile</option>
		    <option value=\"0\""; if($newArt->disp=="0") $content.=" selected"; $content.=">Da verificare</option>
		    <option value=\"-1\""; if($newArt->disp=="-1") $content.=" selected"; $content.=">Esaurito</option>
		  </select>
		  </td>
		  <td align=right>Unit&agrave; di misura</td>
		  <td>";
		 $sql = "SELECT valore FROM misura ORDER BY valore ASC;";
		 $rs_menu = $conn->Execute($sql);
		 $content .= $rs_menu->GetMenu("misura",($newArt->misura!="" ? $newArt->misura : 'pezzi'),false);
		 $rs_menu->Close();
		 $content .= "</td>
		 </tr>
		 <tr>
		   <td colspan=4>Produttore: ";
		  $sql = "SELECT distinct produttore FROM articoli_new WHERE produttore!='' ORDER BY produttore ASC;";
		  $rs_menu = $conn->Execute($sql);
		  $content .= $rs_menu->GetMenu2("produttore",$newArt->produttore,":Seleziona..");
		  $rs_menu->Close();
		 $content .= "&nbsp; altrimenti inserisci uno nuovo <input type=text name=produttore_add size=30 value=\"\"></td>
		 </tr>
		 <tr>
		   <td colspan=4>NOTE<br><textarea name=note_admin cols=100 rows=10>$newArt->note</textarea></td>
		 </tr>
		 <tr>
		 	<td colspan=4 align=center>&nbsp;</td>
		 </tr>";
		 if($newArt->idarticolo!="")  {
		 	$content .= "<tr>
		 			 			 	<td colspan=4 align=center class=tbtit>FORNITORE PRINCIPALE</td>
		 			 			 </tr>
		 			 			 <tr>
		 			 			 	<td colspan=4>";
		 	$qry = "SELECT DISTINCT codice,f.fornitore as fornitore,costo,f.id as id FROM articoli_fornitore a LEFT JOIN
		 			 			 fornitore f ON a.idfornitore=f.id 
		 			 			 WHERE a.idarticolo=$newArt->idarticolo AND principale=1 LIMIT 0,1;";
		 	//die($qry);
		 	$rs2 = $conn->execute($qry);
		 	$content .= '<table width="100%" cellpadding="2" class="content">
		 			 			 			 	<tr>
		 			 			 			 	  <td width="100"><b>CODICE</b></td>
		 			 			 			 	  <td width="200"><b>NOME</b></td>
		 			 			 			 	  <td width="100"><b>COSTO(&euro;)</b></td>
		 			 			 			 	  <td width="100" align="center"><b>AZIONI</b></td>
		 			 			 			 	</tr>';
		 	if($rs2->RecordCount()>0) {
		 		while(!$rs2->EOF) {
		 			$content .= '<tr>
		 			 			 		<td>'.$rs2->Fields("codice").'</td>
		 			 			 		<td>'.$rs2->Fields("fornitore").'</td>
		 			 			 		<td>'.$rs2->Fields("costo").'</td>
		 			 			 		<td align="center"><a href="javascript:;" onClick="modCodici('.$newArt->idarticolo.','.($rs2->Fields("id") ? $rs2->Fields("id") : 0).');"><img src="imgs/ico_edit.gif" /></a>&nbsp;&nbsp;
		 			 			 		<!--<a href="javascript:;" onClick="if(confirm(\'Sei sicuro di voler eliminare questo codice? Proseguire?\')) delCodice('.$newArt->idarticolo.','.$rs2->Fields("id").');"><img src="imgs/ico_delete.gif" /></a>-->
		 			 			 		</td>
		 			 			 		</tr>';
		 			$rs2->MoveNext();
		 		}
		 		$rs2->Close();
		 	}
		 	$content .= "<tr>
		 			 	<td colspan=4 align=center class=tbtit>FORNITORI SECONDARI</td>
		 			 </tr>
		 			 <tr>
		 			 	<td colspan=4>";
		 	$qry = "SELECT DISTINCT codice,f.fornitore as fornitore,costo,f.id as id FROM articoli_fornitore a LEFT JOIN
		 			 fornitore f ON a.idfornitore=f.id 
		 			 WHERE a.idarticolo=$newArt->idarticolo AND principale=0;";
		 	//die($qry);
		 	$rs2 = $conn->execute($qry);
		 	$content .= '<table width="100%" cellpadding="2" class="content">
		 			 			 	<tr>
		 			 			 	  <td width="100"><b>CODICE</b></td>
		 			 			 	  <td width="200"><b>NOME</b></td>
		 			 			 	  <td width="100"><b>COSTO(&euro;)</b></td>
		 			 			 	  <td width="100" align="center"><b>AZIONI</b></td>
		 			 			 	</tr>';
		 	if($rs2->RecordCount()>0) {
		 		while(!$rs2->EOF) {
		 			$content .= '<tr>
		 			 		<td>'.$rs2->Fields("codice").'</td>
		 			 		<td>'.$rs2->Fields("fornitore").'</td>
		 			 		<td>'.$rs2->Fields("costo").'</td>
		 			 		<td align="center">
		 			 		<a href="javascript:;" onClick="modCodici('.$newArt->idarticolo.','.$rs2->Fields("id").');"><img src="imgs/ico_edit.gif" /></a>&nbsp;&nbsp;
		 			 		<a href="javascript:;" onClick="if(confirm(\'Sei sicuro di voler eliminare questo codice? Proseguire?\')) delCodice('.$newArt->idarticolo.','.$rs2->Fields("id").');"><img src="imgs/ico_delete.gif" /></a>&nbsp;&nbsp;
		 			 		<a href="javascript:;" title="IMPOSTA COME PRINCIPALE" onClick="setPrincipale('.$newArt->idarticolo.','.$rs2->Fields("id").');"><img src="imgs/ico_up.gif" /></a>
		 			 		</td>
		 			 		</tr>';
		 			$rs2->MoveNext();
		 		}
		 		$rs2->Close();
		 	}
		 	$content .= '<tr>
		 			 			 	<td colspan="4" id="mod-codice" style="display:none;border:1px solid #3B88C2;width:100%;">
		 			 			 	<p><b>MODIFICA CODICE</b></p>
		 			 			 	<p>Codice: <input type="text" id="codice_mod" size="10" /> Fornitore: ';
		 	$sql = "SELECT fornitore,id FROM fornitore WHERE giardino=3 ORDER BY fornitore ASC;";
		 	$rs_menu = $conn->Execute($sql);
		 	$content .= $rs_menu->GetMenu("idfornitore_mod","",false);
		 	$rs_menu->Close();
		 	$content .= ' Costo: <input type="text" id="costo_mod" size="5" /> <input type="button" id="upd-codice" value="SALVA MODIFICHE"></p>
		 			 			 	</td>
		 			 			 	</tr>';
		 	$content .= '<tr>
		 			 			 	<td colspan="4" id="add-codice" style="border:1px solid #3B88C2;">
		 			 			 	<p><b>AGGIUNGI CODICE FORNITORE SECONDARIO</b></p>
		 			 			 	Codice: <input type="text" id="codice" size="20" /> Fornitore: ';
		 	$sql = "SELECT fornitore,id FROM fornitore WHERE giardino=3 ORDER BY fornitore ASC;";
		 	$rs_menu = $conn->Execute($sql);
		 	$content .= $rs_menu->GetMenu("idfornitore","",false);
		 	$rs_menu->Close();
		 	$content .= ' Se non in elenco <input type="text" id="fornitore_add" size="10"> Costo: <input type="text" id="costo" size="20" /> <input type="button" onClick="salvaCodice('.$newArt->idarticolo.');" value="SALVA NUOVO">
		 			 			 	</td>
		 			 			 	</tr>';
		 	$content .= '</table>';
		 	$content .= "</td>
		 			 </tr>
		 			 <tr>
		 			 	<td colspan=4 align=center>&nbsp;</td>
		 			 </tr>";
		 	############ VARIANTI ####################
		 	$varianti_html = "<tr>
		 			 		 			 	<td colspan=4 align=center class=tbtit>VARIANTI</td>
		 			 		 			 </tr>
		 			 		 			 <tr>
		 			 		 			 	<td colspan=4>";
		 	$qry = "SELECT * FROM varianti  WHERE idarticolo=$newArt->idarticolo;";
		 	//die($qry);
		 	$rs2 = $conn->execute($qry);
		 	$varianti_html .= '<table width="100%" cellpadding="2" class="content">
		 			 		 			 			 	<tr>
		 			 		 			 			 	  <td width="100"><b>VARIANTE</b></td>
		 			 		 			 			 	  <td width="100"><b>CODICE</b></td>
		 			 		 			 			 	  <td width="200"><b>DESCRIZIONE</b></td>
		 			 		 			 			 	  <td width="100"><b>IMMAGINE</b></td>
		 			 		 			 			 	  <td width="100" align="center"><b>AZIONI</b></td>
		 			 		 			 			 	</tr>';
		 	if($rs2->RecordCount()>0) {
		 		while(!$rs2->EOF) {
		 			$varianti_html .= '<tr>
		 			 		 			 		<td>'.$rs2->Fields("nome").'</td>
		 			 		 			 		<td>'.$rs2->Fields("codice").'</td>
		 			 		 			 		<td>'.$rs2->Fields("descrizione").'</td>
		 			 		 			 		<td>'.(file_exists($_SERVER[DOCUMENT_ROOT]."/immagini-mrpiscina/varianti/".$rs2->Fields("image")) ? 
		 			 		 			 		'<img src="/immagini-giardino/varianti/'.$rs2->Fields("image").'" width="100">' : '&nbsp;').'</td>
		 			 		 			 		<td align="center">
		 			 		 			 		<a href="javascript:;" onClick="modVarianteArticolo('.$rs2->Fields("id").');"><img src="imgs/ico_edit.gif" /></a>&nbsp;&nbsp;
		 			 		 			 		<a href="javascript:;" onClick="if(confirm(\'Sei sicuro di voler eliminare questa variante? Proseguire?\')) delVarianteArticolo('.$rs2->Fields("id").');"><img src="imgs/ico_delete.gif" /></a>&nbsp;&nbsp;
		 			 		 			 		</td>
		 			 		 			 		</tr>';
		 			$rs2->MoveNext();
		 		}
		 		$rs2->Close();
		 	}
		 	$varianti_html .= '<tr>
		 			 		 			 			 	<td colspan="4" id="mod-variante-articolo" style="display:none;border:1px solid #3B88C2;width:100%;">
		 			 		 			 			 	<form action="product_new.php" method=post enctype="multipart/form-data">
		 			 		 			 			 	<p><b>MODIFICA VARIANTE</b></p>
		 			 		 			 			 	<p>Nome variante: <input type="text" id="nome_var_mod" name="nome_var_mod" size="20" /></p>
		 			 		 			 			 	<p>Codice: <input type="text" id="codice_var_mod" name="codice_var_mod" size="20" /></p>
		 			 		 			 			 	<p>Descrizione: <input type="text" id="descrizione_var_mod" name="descrizione_var_mod" size="40" /></p>
		 			 		 			 			 	<p>Immagine: <input type="file" id="image_var_mod" name="image_var_mod" size="10" /></p>
		 			 		 			 			 	<p><input type="hidden" id="id_var" name="id_var" value="">
		 			 		 			 			 	<input type="hidden" name="idarticolo_var" value="'.$newArt->idarticolo.'">
		 			 		 			 			 	<input type="hidden" name="cid_var" value="'.$newArt->cid.'">
		 			 		 			 			 	<input type="hidden" name="op" value="updVarianteArticolo">
		 			 		 			 			 	<input type="submit" value="SALVA MODIFICHE"></p>
		 			 		 			 			 	</form>
		 			 		 			 			 	</td>
		 			 		 			 			 	</tr>';
		 	$varianti_html .= '<tr>
		 			 		 			 			 	<td colspan="4" id="add-variante" style="border:1px solid #3B88C2;">
		 			 		 			 			 	<form action="product_new.php" method=post enctype="multipart/form-data">
		 			 		 			 			 	<p><b>AGGIUNGI VARIANTE</b></p>
		 			 		 			 			 	<p>Nome variante: <input type="text" name="nome_var_add" size="20" /> 
		 			 		 			 			 	Codice: <input type="text" name="codice_var_add" size="20" /> 
		 			 		 			 			 	Descrizione: <input type="text" name="descrizione_var_add" size="20" /></p> 
		 			 		 			 			 	<p>Immagine: <input type="file" name="image_var_add" size="20" />
		 			 		 			 			    <input type="hidden" name="op" value="addVarianteArticolo">
		 			 		 			 			    <input type="hidden" name="idarticolo_var" value="'.$newArt->idarticolo.'">
		 			 		 			 			    <input type="hidden" name="cid_var" value="'.$newArt->cid.'"></p>
		 			 		 			 			 	<p><input type="submit" value="SALVA NUOVO"></p>
		 			 		 			 			 	</form>
		 			 			 	</td>
		 			 			 	</tr>';
		 	$varianti_html .= '</table>';
		 	$varianti_html .= "</td>
		 			 </tr>
		 			 <tr>
		 			 	<td colspan=4 align=center>&nbsp;</td>
		 			 </tr>";
		 }
		 $content .= "<tr>
		  <td colspan=4 align=center valign=top>
		  ".$ricerca."
		  </td>
		  </tr>
		  <tr>
		 	<td colspan=4 align=center>&nbsp;</td>
		 </tr>
		 <!--<tr>
		 	<td colspan=4 align=center class=error>Attributi per la Ricerca</td>
		 </tr>-->";
		 if($newArt->idarticolo!="")  {
		 	$content .= "<tr>
				 <td colspan=4 align=center valign=top>
				   <iframe width=720 height=300 src=\"product_new.php?op=get_correlati&idarticolo=$newArt->idarticolo\" scrolling=\"no\"></iframe>
				 </td>
			 </tr>
			 <tr>
				 <td colspan=4 align=center valign=top>
				   <iframe width=720 height=300 src=\"product_new.php?op=get_categorie&idarticolo=$newArt->idarticolo\" scrolling=\"no\"></iframe>
				 </td>
			 </tr>";
		 }
		 $content .= "
		 <tr>
		 <td align=right valign=top><a href=javascript:; onclick=\"showHide('meta');\"><img src=\"imgs/ico_indicizzazione.gif\" border=0></a></td>
		 <td colspan=3><a href=javascript:; onclick=\"showHide('meta');\">Indicizza questo prodotto</a><div id=meta style=\"visibility:hidden; display:none;\">
		 <table width=550 class=content border=0 cellpadding=2>
		   <tr>
		    <td width=100 align=right valign=top>Permalink:</td>
			<td valign=top><input type=text name=hidden size=50 value=\"$hidden\"></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Titolo pagina:<br>Tag &lt;title&gt;</td>
			<td valign=top><textarea name=tagtitle rows=5 cols=100>$tagtitle</textarea></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Parole chiave:<br>Meta-tag &lt;keywords&gt;</td>
			<td valign=top><textarea name=tagkey rows=5 cols=100>$tagkey</textarea></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Descrizione pagina:<br>Meta-tag &lt;description&gt;</td>
			<td valign=top><textarea name=tagdesc rows=5 cols=100>$tagdesc</textarea></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Titolo documento:<br>Meta-tag &lt;title&gt;</td>
			<td valign=top><textarea name=metatitle rows=5 cols=100>$metatitle</textarea></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Frasi documento:<br>Meta-tag &lt;Keyphrase&gt;</td>
			<td valign=top><textarea name=metakey rows=5 cols=100>$metakey</textarea></td>
		   </tr>
		   <tr>
		    <td width=100 align=right valign=top>Descrizione:<br>Meta-tag &lt;http-equiv=\"description\"&gt;</td>
			<td valign=top><textarea name=metadesc rows=5 cols=100>$metadesc</textarea></td>
		   </tr>
		 </table>
		</div>
	   </td>
	  </tr>";
		 $content .= "<tr><td colspan=4 align=center class=content>&nbsp;</td></tr>\n";
		 $content .= "<tr><td colspan=4>
		 $hidden_id
		 <input type=image src=\"imgs/ico_save.gif\" title=Salva onClick=\"return control_articolo();\" width=16 height=16>&nbsp;&nbsp;<a class=content href=\"javascript:document.formarticolo.submit();\" onClick=\"return control_articolo();\">Salva</a> $button</td></tr></table></div></td></tr></form>";
		 $content .= $varianti_html;
		 $content .= "</table>";
		 break;
		 	
			case "get_correlati":
				$idarticolo = $_GET['idarticolo'];
				$newArt = new articoli($idarticolo);
				$content = "<html>
				<head><title></title>
				<link href=\"style/style.css\" rel=\"stylesheet\" type=\"text/css\"></head>
				<body>
				<table class=content width=700 cellpadding=2 cellspacing=0 border=1>
					 <tr>
					   <td class=error width=100% align=center>ARTICOLI CORRELATI</td>
					 </tr>
					 <tr>
					   <td width=100% align=center>".$newArt->getCorrelati()."</td>
					 </tr>
					 <form name=addprodcorr action=\"product_new.php\" method=POST>
					 <tr>
					   <td class=error>Aggiungi nuovo articolo correlato</td>
					 </tr>
					 <tr>
					   <td>Seleziona:";
				$sql = "SELECT titolo1,idarticolo FROM articoli_new WHERE idarticolo != $newArt->idarticolo AND lang='$lang' ORDER BY titolo1 ASC;";
				$rs_menu = $conn->Execute($sql);
				$content .= $rs_menu->GetMenu("idarticolo2","",false,false,0,"style='width:500px'");
				$rs_menu->Close();
				$content .= "<input type=submit value=AGGIUNGI>
		 <input type=hidden name=idarticolo1 value=\"$newArt->idarticolo\">
		 <input type=hidden name=op value=\"add_correlati\">
				</td>
					 </tr>
					 </form>
				   </table>
				 </body>
				</html>";
				die($content);
				break;
					
			case "add_correlati":
				$idarticolo1 = $_POST['idarticolo1'];
				$idarticolo2 = $_POST['idarticolo2'];
				articoli::addCorrelati($idarticolo1,$idarticolo2);
				header("Location:product_new.php?op=get_correlati&idarticolo=$idarticolo1");
				die();
				break;
					
			case "del_correlati":
				$idarticolo1 = $_GET['idarticolo1'];
				$idarticolo2 = $_GET['idarticolo2'];
				articoli::delCorrelati($idarticolo1,$idarticolo2);
				header("Location:product_new.php?op=get_correlati&idarticolo=$idarticolo1");
				die();
				break;
					
			case "del_correlati_import":
				$idarticolo = $_GET['idarticolo'];
				$codice = $_GET['codice'];
				$newArt = new articoli($idarticolo);
				$newArt->delCorrelatiImport($codice);
				header("Location:product_new.php?op=get_correlati&idarticolo=$idarticolo");
				die();
				break;
					
			case "get_categorie":
				$idarticolo = $_GET['idarticolo'];
				$newArt = new articoli($idarticolo);
				$content = "<html>
				<head><title></title>
				<link href=\"style/style.css\" rel=\"stylesheet\" type=\"text/css\"></head>
				<body>
				<table class=content width=700 cellpadding=2 cellspacing=0 border=1>
					 <tr>
					   <td class=error width=100% align=center>CATEGORIE CORRELATE</td>
					 </tr>
					 <tr>
					   <td width=100% align=center>".$newArt->getCategorie()."</td>
					 </tr>
					 <form name=addprodcorr action=\"product_new.php\" method=POST>
					 <tr>
					   <td class=error>Aggiungi nuova Categoria correlata</td>
					 </tr>
					 <tr>
					   <td>Seleziona:";
				$sql = "SELECT titolo,cid FROM categorie WHERE lang='$lang' ORDER BY titolo ASC;";
				$rs_menu = $conn->Execute($sql);
				$content .= $rs_menu->GetMenu("cid",$currentCat->titolo,false);
				$rs_menu->Close();
				$content .= "<input type=submit value=AGGIUNGI>
		 <input type=hidden name=idarticolo value=\"$newArt->idarticolo\">
		 <input type=hidden name=op value=\"add_categoria\">
				</td>
					 </tr>
					 </form>
				   </table>
				 </body>
				</html>";
				die($content);
				break;
					
			case "add_categoria":
				$idarticolo = $_POST['idarticolo'];
				$cid = $_POST['cid'];
				articoli::addCategoria($idarticolo,$cid);
				header("Location:product_new.php?op=get_categorie&idarticolo=$idarticolo");
				die();
				break;
					
			case "del_categoria":
				$idarticolo = $_GET['idarticolo'];
				$cid = $_GET['cid'];
				articoli::delCategoria($idarticolo,$cid);
				header("Location:product_new.php?op=get_categorie&idarticolo=$idarticolo");
				die();
				break;
					
			case "save":
				if($idfather == "")
				$idfather = 0;
				$newCat = new category('',$titolos,$desc,$lang,$idfather,$tagtitles,$tagkeys,$tagdescs,$metatitles, $metakeys, $metadescs, $hiddens);
				$error = $newCat->save();
				if($error == "0")
				header("Location:$currentpage");
				else  {
					$content = $error;
				}
				break;
					
			case "up":
				$newCat = new category($cids);
				$error = $newCat->up();
				if($error == "0")
				header("Location:$currentpage");
				else  {
					$content = $error;
				}
				break;
					
			case "down":
				$newCat = new category($cids);
				$error = $newCat->down();
				if($error == "0")
				header("Location:$currentpage");
				else  {
					$content = $error;
				}
				break;
					
			case "update":
				//controllo se � un servizio o sottocat
				$desc = $_POST['desc_update'];
				$newCat = new category($cids);
				$error = $newCat->update($titolos,$desc,$tagtitles,$tagkeys,$tagdescs,$metatitles, $metakeys, $metadescs, $hiddens);
				if($error == "0")
				header("Location:$currentpage");
				else  {
					$content = $error;
				}
				break;

			case "del":
				$newCat = new category($cids);
				$error = $newCat->delete();
				if($error == "0")
				header("Location:product_new.php?op=product&cid=".$newCat->idfather."&percorso=$currentpage");
				else  {
					$content = printError($error);
				}
				break;
					
			case "activecat":
				$newCat = new category($cids);
				$error = $newCat->active();
				if($error == "0")
				header("Location:product_new.php?op=product&cid=".$newCat->idfather."&percorso=$currentpage");
				else  {
					$content = printError($error);
				}
				break;
					
			case "disactivecat":
				$newCat = new category($cids);
				$error = $newCat->disactive();
				if($error == "0")
				header("Location:product_new.php?op=product&cid=".$newCat->idfather."&percorso=$currentpage");
				else  {
					$content = printError($error);
				}
				break;
					
			case "save_art":
				//controllo la presenza della virgola nei prezzi
				$prezzo1 = str_replace(",",".",$prezzo1);
				$prezzo2 = str_replace(",",".",$prezzo2);
				$spedizione = str_replace(",",".",$spedizione);
				$spedizione2 = str_replace(",",".",$spedizione2);
				$costo = str_replace(",",".",$costo);
				if($multiplo=="") $multiplo = 0;
				$newArt = new articoli("",$cids,$codice,$titolo1,$titolo2,$desc,$image_tmb,$image,$image_big,$prezzo1,$prezzo2,$spedizione,$spedizione2,$promozione,$vetrina,$novita,$minimo,$lang,$peso,$video,$scheda,$disp,'n',$tagtitles,$tagkeys,$tagdescs,$metatitles, $metakeys, $metadescs, $hiddens, $correlato1, $correlato2, $correlato3,$import,$fornitore,$costo,0,$produttore,$misura,$note,$multiplo);
				$content = printError($newArt->save($varianti),"product_new.php?cid=$cids&op=product&percorso=$percorso");
				break;
					
			case "update_art":
				$prezzo1 = str_replace(",",".",$prezzo1);
				$prezzo2 = str_replace(",",".",$prezzo2);
				$spedizione = str_replace(",",".",$spedizione);
				$spedizione2 = str_replace(",",".",$spedizione2);
				$attributo = $_POST['attributo'];
				$newArt = new articoli($idarticolos);
				if($multiplo=="") $multiplo = 0;
				$content = printError($newArt->update($cids,$codice,$titolo1,$titolo2,$desc,$image,$image_big,$prezzo1,$prezzo2,$spedizione,$spedizione2,$promozione,$vetrina,$novita,$minimo,$peso,$video,$scheda,$disp,$tagtitles,$tagkeys,$tagdescs,$metatitles, $metakeys, $metadescs, $hiddens, $fornitore, $attributo,$costo,$produttore,$varianti,$misura,$note,$multiplo));
				break;
					
			case "up_art":
				$newArt = new articoli($idarticolos);
				$error = $newArt->up();
				if($error == "0")
				header("Location:$currentpage");
				else  {
					$content = $error;
				}
				break;
					
			case "down_art":
				$newArt = new articoli($idarticolos);
				$error = $newArt->down();
				if($error == "0")
				header("Location:$currentpage");
				else  {
					$content = $error;
				}
				break;

			case "del_art":
				$newArt = new articoli($idarticolos);
				$error = $newArt->delete();
				if($error == "0")
				header("Location:product_new.php?cid=$newArt->cid&op=product&percorso=$percorso");
				else  {
					$content = $error;
				}
				break;
					
			case "active":
				$newArt = new articoli($idarticolos);
				$error = $newArt->active();
				if($error == "0")
				header("Location:product_new.php?cid=$newArt->cid&op=product&percorso=$percorso");
				else  {
					$content = $error;
				}
				break;
					
			case "disactive":
				$newArt = new articoli($idarticolos);
				$error = $newArt->disactive();
				if($error == "0")
				header("Location:product_new.php?cid=$newArt->cid&op=product&percorso=$percorso");
				else  {
					$content = $error;
				}
				break;

			case "bannerIn":
				$newArt = new articoli($idarticolos);
				$error = $newArt->bannerIn();
				if($error == "0")
				header("Location:product_new.php?cid=$newArt->cid&op=product&percorso=$percorso");
				else  {
					$content = $error;
				}
				break;
					
			case "bannerOut":
				$newArt = new articoli($idarticolos);
				$error = $newArt->bannerOut();
				if($error == "0")
				header("Location:product_new.php?cid=$newArt->cid&op=product&percorso=$percorso");
				else  {
					$content = $error;
				}
				break;
				
			case "vetrinaIn":
				$newArt = new articoli($idarticolos);
				$error = $newArt->vetrinaCatIn();
				if($error == "0")
				header("Location:product_new.php?cid=$newArt->cid&op=product&percorso=$percorso");
				else  {
					$content = $error;
				}
				break;
					
			case "vetrinaOut":
				$newArt = new articoli($idarticolos);
				$error = $newArt->vetrinaCatOut();
				if($error == "0")
				header("Location:product_new.php?cid=$newArt->cid&op=product&percorso=$percorso");
				else  {
					$content = $error;
				}
				break;
					
			case "duplica":
				$newArt = new articoli($idarticolos);
				$newArt->fornitore = addslashes($newArt->fornitore);
				$content = printError($newArt->save(),"product_new.php?cid=$newArt->cid&op=product&percorso=$percorso");
				break;
					
			case "upd_field":
				$field = $_POST['field'];
				$value = trim($_POST['value']);
				$idarticolo = $_POST['idarticolo'];
				die(articoli::update_field($field,$value,$idarticolo));
				break;
			
			case "upd_costo":
					$idfornitore = $_POST['idfornitore'];
					$value = trim($_POST['value']);
					$idarticolo = $_POST['idarticolo'];
					die(articoli::update_costo($idfornitore,$value,$idarticolo));
			break;
			
			case "upd_codice":
				$idfornitore = $_POST['idfornitore'];
				$value = trim($_POST['value']);
				$idarticolo = $_POST['idarticolo'];
				die(articoli::update_codice($idfornitore,$value,$idarticolo));
				break;
					
			case "promozioni":
				$cid = $_GET['cid'];
				$content = '<div id="promozioni">'.articoli::getPromozioni($cid).'</div>';
				break;
					
			case "del_prom":
				$tipo = $_POST['tipo'];
				$idarticolo = $_POST['idarticolo'];
				$cid = $_POST['cid'];
				$newArt = new articoli($idarticolo);
				$error = $newArt->{$tipo."Out"}();
				die(articoli::getPromozioni($cid));
				break;
					
			case "add_prom":
				$tipo = $_POST['tipo'];
				$idarticolo = $_POST['idarticolo'];
				$cid = $_POST['cid'];
				$newArt = new articoli($idarticolo);
				$error = $newArt->{$tipo."In"}();
				die(articoli::getPromozioni($cid));
				break;
					
			case "get_buoni":
				$content = '<div id="grid_buoni">'.articoli::getBuoni().'</div>';
				break;
					
			case "active_buono":
				$idbuono = $_GET['idbuono'];
				$error = articoli::activeBuono($idbuono);
				header("Location:product_new.php?op=get_buoni");
				die();
				break;
					
			case "disactive_buono":
				$idbuono = $_GET['idbuono'];
				$error = articoli::disactiveBuono($idbuono);
				header("Location:product_new.php?op=get_buoni");
				die();
				break;
					
			case "addbuono":
				$codice = $_POST['codice'];
				$valore = $_POST['valore'];
				if($valore=="") $valore = 0;
				$perc = $_POST['percentuale'];
				if($perc=="") $perc=0;
				$minimo = $_POST['minimo'];
				if($minimo=="")  $minimo = 0;
				if($_POST['start']!="") {
					list($g,$m,$a) = explode("/",$_POST['start']);
					$start = "$a-$m-$g";
				}
				if($_POST['end']!="") {
					list($g,$m,$a) = explode("/",$_POST['end']);
					$end = "$a-$m-$g";
				}
				$error = articoli::addBuono($codice,$valore,$perc,$minimo,$start,$end);
				die(articoli::getBuoni());
				break;
					
			case "updbuono":
				$idbuono = $_POST['idbuono'];
				$codice = $_POST['codice'];
				$valore = $_POST['valore'];
				if($valore=="") $valore = 0;
				$perc = $_POST['percentuale'];
				if($perc=="") $perc=0;
				$minimo = $_POST['minimo'];
				if($minimo=="")  $minimo = 0;
				if($_POST['start']!="") {
					list($g,$m,$a) = explode("/",$_POST['start']);
					$start = "$a-$m-$g";
				}
				if($_POST['end']!="") {
					list($g,$m,$a) = explode("/",$_POST['end']);
					$end = "$a-$m-$g";
				}
				$error = articoli::updBuono($codice,$valore,$perc,$minimo,$idbuono,$start,$end);
				die(articoli::getBuoni());
				break;
					
			case "delbuono":
				$idbuono = $_POST['idbuono'];
				$error = articoli::delBuono($idbuono);
				die(articoli::getBuoni());
				break;
					
			case "list_categorie":
				die(category::json_cat());
				break;
					
			case "list_articoli":
				die(articoli::json_articoli());
				break;
					
			case "list_gruppi":
				die(group::json_gruppi());
				break;
					
			case "list_users":
				die(webuser::json_users());
				break;
					
			case "addcat":
				$cid = $_POST['cid'];
				$idbuono = $_POST['idbuono'];
				$error = articoli::addBuonoCat($idbuono,$cid);
				die(articoli::getBuoni());
				break;
					
			case "delcat":
				$cid = $_POST['cid'];
				$idbuono = $_POST['idbuono'];
				$error = articoli::delBuonoCat($idbuono,$cid);
				die(articoli::getBuoni());
				break;
					
			case "addart":
				$idarticolo = $_POST['idarticolo'];
				$idbuono = $_POST['idbuono'];
				$error = articoli::addBuonoArt($idbuono,$idarticolo);
				die(articoli::getBuoni());
				break;
					
			case "delart":
				$idarticolo = $_POST['idarticolo'];
				$idbuono = $_POST['idbuono'];
				$error = articoli::delBuonoArt($idbuono,$idarticolo);
				die(articoli::getBuoni());
				break;
					
			case "addgruppo":
				$idgruppo = $_POST['idgruppo'];
				$idbuono = $_POST['idbuono'];
				$error = articoli::addBuonoGruppo($idbuono,$idgruppo);
				die(articoli::getBuoni());
				break;
					
			case "delgruppo":
				$idgruppo = $_POST['idgruppo'];
				$idbuono = $_POST['idbuono'];
				$error = articoli::delBuonoGruppo($idbuono,$idgruppo);
				die(articoli::getBuoni());
				break;
					
			case "adduser":
				$idwebuser = $_POST['idwebuser'];
				$idbuono = $_POST['idbuono'];
				$error = articoli::addBuonoWebuser($idbuono,$idwebuser);
				die(articoli::getBuoni());
				break;
					
			case "deluser":
				$idwebuser = $_POST['idwebuser'];
				$idbuono = $_POST['idbuono'];
				$error = articoli::delBuonoWebuser($idbuono,$idwebuser);
				die(articoli::getBuoni());
				break;
					
			case "get_csv":
				$cid = $_GET['cid'];
				articoli::getCsv($cid);
				die();
				break;
					
			case "import":
				$content = "<table width=400 class=content cellpadding=3>
			  	<form name=\"import\" action=product_new.php method=post enctype=\"multipart/form-data\">
			  	<tr><td class=tbtit colspan=2>Importa articoli</td></tr>
				  <tr>
				   <td class=content align=right width=100>File CSV:</td><td><input type=file size=60 name=csv></td>
				  </tr>
				  <tr>
				   <td colspan=2 align=center>
				   <input type='hidden' name='op' value='doimport'>
				  <input type=image src=\"imgs/ico_save.gif\" title=Salva width=16 height=16> - <a href=\"javascript:document.import.submit();\">IMPORTA</a></td></tr>
				  </form>
				  <form name=\"import2\" action=product_new.php method=post enctype=\"multipart/form-data\">
			  	<tr><td class=tbtit colspan=2>Importa articoli solo dati</td></tr>
				  <tr>
				   <td class=content align=right width=100>File CSV:</td><td><input type=file size=60 name=csv></td>
				  </tr>
				  <tr>
				   <td colspan=2 align=center>
				   <input type='hidden' name='op' value='doimport_dati'>
				  <input type=image src=\"imgs/ico_save.gif\" title=Salva width=16 height=16> - <a href=\"javascript:document.import.submit();\">IMPORTA</a></td></tr>
				  </form>
				 </table>";	
				break;
					
			case "import_ordine_minimo":
				$content = "<table width=400 class=content cellpadding=3>
			  	<form name=\"import\" action=product_new.php method=post enctype=\"multipart/form-data\">
			  	<tr><td class=tbtit colspan=2>Importa Ordine Minimo</td></tr>
				  <tr>
				   <td class=content align=right width=100>File CSV:</td><td><input type=file size=60 name=csv></td>
				  </tr>
				  <tr>
				   <td colspan=2 align=center>
				   <input type='hidden' name='op' value='doimport_ordine_minimo'>
				  <input type=image src=\"imgs/ico_save.gif\" title=Salva width=16 height=16> - <a href=\"javascript:document.import.submit();\">IMPORTA</a></td></tr>
				  </form>
				 </table>";	
				break;
					
			case "doimport":
				$csv = $_FILES['csv'];
				$content = printError(articoli::import($csv));
				break;
				
				case "doimport_dati":
					//$charset = "UTF-8";
					//setlocale(LC_ALL, 'it_IT.UTF-8');
					$csv = $_FILES['csv'];
					$content = printError(articoli::importNoImage($csv));
					break;
					
			case "doimport_ordine_minimo":
				$csv = $_FILES['csv'];
				$content = printError(articoli::importOrdineMinimo($csv));
				break;
					
			case "correla_gruppo":
				$cid_corr = $_POST['cid_corr'];
				$cid_from = $_POST['cid_from'];
				$content = articoli::addCategoriaGruppo($cid_from,$cid_corr);
				break;
					
			case "search":
				$search = $_POST['search'];
				$content = articoli::search($search);
				break;
					
			case "saveAttr":
				$nome = $_POST['nome'];
				$cid = $_POST['cid'];
				$error = category::saveAttributo(utf8_decode($nome),$cid);
				if($error == "0") {
				 die(category::getAttributi($cid));
				} else  {
					$content = $error;
				}
				break;
					
			case "updateAttr":
				$nome = $_POST['nome'];
				$id = $_POST['id'];
				$cid = $_POST['cid'];
				$error = category::updateAttributo(utf8_decode($nome),$id);
				if($error == "0") {
				 die(category::getAttributi($cid));
				} else  {
					$content = $error;
				}
				break;
					
			case "delAttributo":
				$id = $_POST['id'];
				$cid = $_POST['cid'];
				$error = category::deleteAttributo($id);
				if($error == "0") {
				 die(category::getAttributi($cid));
				} else  {
					$content = $error;
				}
				break;
					
			case "getAttributo":
				$id = $_POST['id'];
				die(category::getAttributo($id));
				break;
				
############################## VARIANTI ###############################################
			  
			  case "anag_varianti":
				$content = '<table width=600 class=content cellpadding=3>
				<tr><td class=tbtit colspan=2>ANAGRAFICA VARIANTI</td></tr>
				  <tr>
				  <td><div style="border:1px solid #3B88C2;padding:10px">
							  <p><input id="btn_new_attr" type="button" value="NUOVA VARIANTE" onClick="addVariante();"></p>
							  <div id="add_attr" style="display:none;">
							    <p>Nome Variante: <input type="text" id="nome_attr"  size="30"></p>
							    <p>Seleziona le categorie</p>
							    <p><select id="cids" name="cids[]" multiple="multiple" size="10">'.category::getCategorieFull().'</select></p>
							    <p><input type="button" value="SALVA" onClick="saveVariante();"></p>
							  </div>
							  <div id="list_attr">
							   '.Variante::listAttributi().'
							  </div>
							 </div>
							 </td>
				  </tr>
				</table>';
			  	break;	
				
			  case "getListAttributi":
			    $cid = $_POST['cid'];
				die(Variante::listAttributi());
			  break;
			  
			  case "saveVariante":
			    $par = stripslashes($_REQUEST['json']);
				$json = json_decode($par);
				$error = Variante::saveAttributo(utf8_decode($json->nome),$json->cids);
				die('{json:'.json_encode(Variante::listAttributi()).'}');
			  break;
			  
			  case "getVariante":
			    $idattributo = $_POST['idattributo'];
				die(Variante::getAttributo($idattributo));
			  break;
			  
			  case "updVariante":
			    $par = stripslashes($_REQUEST['json']);
				$json = json_decode($par);
			    $idattributo = $json->idattributo;
				$error = Variante::updAttributo($idattributo,utf8_decode($json->nome),$json->cids);
				die('{json:'.json_encode(Variante::listAttributi()).'}');
			  break;
			  
			  case "delVariante":
			    $idattributo = $_POST['idattributo'];
				$cid = $_POST['cid'];
				$error = Variante::delAttributo($idattributo);
				die(Variante::listAttributi());
			  break;
			  
			  case "getValori":
			    $idattributo = $_POST['idattributo'];
				$attributo = Variante::getNomeAttributo($idattributo);
				die('{json:'.json_encode(Variante::listValori($idattributo)).',attributo:'.json_encode($attributo).'}');
			  break;
			  
			  case "saveValore":
			    $par = stripslashes($_REQUEST['json']);
				$json = json_decode($par);
				$error = Variante::saveValore($json->idattributo,utf8_decode($json->valore),$json->start,$json->end,$json->passo);
				die('{json:'.json_encode(Variante::listValori($json->idattributo)).'}');
			  break;
			  
			  case "getValore":
			    $idattributo = $_POST['idattributo'];
				die(Variante::getAttributo($idattributo));
			  break;
			  
			  case "updValore":
			    $par = stripslashes($_REQUEST['json']);
				$json = json_decode($par);
			    $idvalore = $json->idvalore;
				$valore = $json->valore;
				$idattributo = $json->idattributo;
				$error = Variante::updValore($idvalore,utf8_decode($valore));
				die('{json:'.json_encode(Variante::listValori($json->idattributo)).'}');
			  break;
			  
			  case "delValore":
			    $idvalore = $_POST['idvalore'];
				$idattributo = $_POST['idattributo'];
				$error = Variante::delValore($idvalore);
				die(Variante::listValori($idattributo));
			  break;
########################## SCONTISTICA ########################################################
			  case "scontistica":
			  	$elenco_cat = category::getSottoCategorie();
			  	$content = '<table width=600 class=content cellpadding=3>
				<tr><td class=tbtit colspan=2>GESTIONE SCONTISTICHE</td></tr>
				  <tr>
				  <td>
				  <div id="list_attr">
							   '.articoli::listSconti().'
				  </div>
				  <div style="border:1px solid #3B88C2;padding:10px">
							  <p><input id="btn_new_attr" type="button" value="NUOVO SCONTO" onClick="addSconto();"></p>
							  <div id="add_sconto" style="display:none;">
							    <p>Titolo sconto: <input type="text" id="titolo" size="30"></p>
							    <p>Sconto in %: <input type="text" id="sconto" size="5"> per 
							    <select id="spedizione" name="spedizione">
							    <option value="0">PREZZO LISTINO</option>
							    <option value="1">PREZZO SCONTATO</option>
							    <option value="2">ENTRAMBI I PREZZI</option>
							    <option value="3">SPEDIZIONE</option>
							    </select>
							    </p>
							    <p>Dal: <input type=text size=10 name=dal id=dal onBlur="check_date(this)"><a href="javascript:;" onclick="return showCalendar(\'dal\', \'%d/%m/%Y\');"><img src="imgs/date.gif" border=0 width=20 height=18 alt="Calendar"></a></p>
							    <p>Al: <input type=text size=10 name=al id=al onBlur="check_date(this)"><a href="javascript:;" onclick="return showCalendar(\'al\', \'%d/%m/%Y\');"><img src="imgs/date.gif" border=0 width=20 height=18 alt="Calendar"></a></p>
							    <p><input type="radio" name="tipo" value="1" onClick="selTipo(this);" checked>SELEZIONA LE CATEGORIE</p>
							    <p id="cont-cat"><select id="cids" name="cids[]" multiple="multiple" size="10">'.$elenco_cat.'</select></p>
							    <p><input type="radio" name="tipo" value="2" onClick="selTipo(this);">SELEZIONA GLI ARTICOLI</p>
							    <p>Seleziona una categoria <select id="cid" name="cid" onChange="listArticoli();">
							    <option value="">Seleziona..</option>
							    '.$elenco_cat.'
							    </select></p>
							    <p id="cont-art" style="display:none;"><select id="idarticolo" name="idarticolo[]" multiple="multiple" size="10"></select></p>
							     <p><input type="radio" name="tipo" value="3" onClick="selTipo(this);">SELEZIONA IL FORNITORE</p>
							     <p>';
							      $sql = "SELECT fornitore FROM fornitore WHERE fornitore!='' AND giardino=3 ORDER BY fornitore ASC;";
								  $rs_menu = $conn->Execute($sql);
								  $content .= $rs_menu->GetMenu2("fornitore","",":Seleziona..",false,0,"id=fornitore");
								  $rs_menu->Close();
							     $content .= '</p>
							    <p><input type="button" value="SALVA" onClick="saveSconto();"></p>
							  </div>
							  <div id="mod_attr" style="display:none;">
							    <p><b>MODIFICA SCONTO</b></p>
							    <p>Titolo sconto: <input type="text" id="titolo_edit" size="30"></p>
							    <p>Sconto in %: <input type="text" id="sconto_edit" size="5"> per 
							    <select id="spedizione_edit" name="spedizione_edit">
							    <option value="0">PREZZO LISTINO</option>
							    <option value="1">PREZZO SCONTATO</option>
							    <option value="2">ENTRAMBI I PREZZI</option>
							    <option value="3">SPEDIZIONE</option>
							    </select>
							    </p>
							    <p>Dal: <input type=text size=10 name=dal id=dal_edit onBlur="check_date(this)"><a href="javascript:;" onclick="return showCalendar(\'dal_edit\', \'%d/%m/%Y\');"><img src="imgs/date.gif" border=0 width=20 height=18 alt="Calendar"></a></p>
							    <p>Al: <input type=text size=10 name=al id=al_edit onBlur="check_date(this)"><a href="javascript:;" onclick="return showCalendar(\'al_edit\', \'%d/%m/%Y\');"><img src="imgs/date.gif" border=0 width=20 height=18 alt="Calendar"></a></p>
							    <p><input type="radio" name="tipo_edit" value="1" onClick="selTipoEdit(this);" checked>SELEZIONA LE CATEGORIE</p>
							    <p id="cont-cat_edit"><select id="cids_edit" name="cids[]" multiple="multiple" size="10">'.$elenco_cat.'</select></p>
							    <p><input type="radio" name="tipo_edit" value="2" onClick="selTipoEdit(this);">SELEZIONA GLI ARTICOLI</p>
							    <p>Seleziona una categoria <select id="cid_edit" name="cid">
							    <option value="">Seleziona..</option>
							    '.$elenco_cat.'
							    </select></p>
							    <p id="cont-art_edit" style="display:none;"><select id="idarticolo_edit" name="idarticolo[]" multiple="multiple" size="10"></select></p>
							    <p><input type="radio" name="tipo_edit" value="3" onClick="selTipoEdit(this);">SELEZIONA IL FORNITORE</p>
							     <p>';
							      $sql = "SELECT fornitore FROM fornitore WHERE fornitore!='' AND giardino=3 ORDER BY fornitore ASC;";
								  $rs_menu = $conn->Execute($sql);
								  $content .= $rs_menu->GetMenu2("fornitore_edit","",":Seleziona..",false,0,"id=fornitore_edit");
								  $rs_menu->Close();
							     $content .= '</p>
							    <p><input type="hidden" id="idsconto" value="" /><input type="button" value="SALVA" onClick="updateSconto();"></p>
							  </div>
							 </div>
							 </td>
				  </tr>
				</table>';
			  	break;
			  	
			  case "saveSconto":
			    $par = stripslashes($_REQUEST['json']);
				$json = json_decode($par);
				articoli::saveSconto($json);
				die('{json:'.json_encode(articoli::listSconti()).'}');
			  break;
			  
			  case "updateSconto":
			    $par = stripslashes($_REQUEST['json']);
				$json = json_decode($par);
				articoli::updateSconto($json);
				die('{json:'.json_encode(articoli::listSconti()).'}');
			  break;
			  
			  case "deleteSconto":
			  	$id = $_POST['id'];
			  	articoli::deleteSconto($id);
			  	die('{json:'.json_encode(articoli::listSconti()).'}');
			  	break;
			  
			  case "getSconto":
			  	die(articoli::getSconto($_POST['id']));
			  	break;
			  	
			  case "getListArticoli":
			  	$cid = $_POST['cid'];
			  	die(articoli::json_articoli($cid));
			  	break;
###############################################################################################
				
			case "anag_prod":
				$content = "<table width=600 class=content cellpadding=3>
				<tr><td class=tbtit colspan=2>ANAGRAFICA FORNITORI</td></tr>
			  	<tr>
			  	<td colspan=2>
			  	<table width=100% class=content cellpadding=2>
			  	<tr>
			  	<td class=tbtit width=400>FORNITORE</td>
			  	<td class=tbtit align=center>AZIONI</td>
			  	</tr>";
		 $qry = "SELECT id,fornitore FROM fornitore WHERE giardino=3 ORDER BY fornitore;";
		 $rs = $conn->Execute($qry);
		 if($rs->RecordCount()>0) {
		 	while(!$rs->EOF) {
		 		$content .= '<tr>
		 		<td style="border-bottom:1px solid #3B88C2;">'.$rs->Fields("fornitore").'</td>
		 		<td align="center" style="border-bottom:1px solid #3B88C2;">
		 		<a href="javascript:;" onClick="modFornitore('.$rs->Fields("id").')"><img src="imgs/ico_edit.gif" /></a>&nbsp;&nbsp;
		 		<a href="javascript:;" onClick="if(confirm(\'Sei sicuro di voler eliminare questo Fornitore? Procedere?\')) delFornitore('.$rs->Fields("id").')"><img src="imgs/ico_delete.gif" /></a>
		 		</td>
		 		</tr>';
		 		$rs->MoveNext();
		 	}
		 	$rs->Close();
		 }
		 $content .= '<tr>
		 <td colspan="2" id="mod-fornitore" style="display:none;border:1px solid #3B88C2;">
		 <p><b>MODIFICA FORNITORE</b></p>
		 <p>Fornitore:</p>
		 <p><input type="text" id="fornitore_mod" size="20" /></p>
		 <p><input type="button" id="upd-fornitore" value="SALVA MODIFICHE"></p>
		 </td>
		 </tr>
		 <tr>
		 <td colspan="2" id="add-fornitore" style="border:1px solid #3B88C2;">
		 <p><b>AGGIUNGI NUOVO FORNITORE</b></p>
		 <p>Fornitore:</p>
		 <p><input type="text" id="fornitore" size="20" /></p>
		 <p><input type="button" onClick="salvaFornitore();" value="SALVA NUOVO"></p>
		 </td>
		 </tr>';
		 $content .= "</table></td></tr>
		 <form name=search action=product_new.php method=post>
				  <tr>
				  <tr><td class=tbtit colspan=2>ANAGRAFICA PRODUTTORI</td></tr>
				   <td align=left>Seleziona il PRODUTTORE ";
		  $sql = "SELECT distinct produttore FROM articoli_new WHERE produttore!='' AND giardino=3 ORDER BY produttore ASC;";
		  $rs_menu = $conn->Execute($sql);
		  $content .= $rs_menu->GetMenu2("produttore","",false);
		  $rs_menu->Close();
		 $content .= "<input type='hidden' name='op' value='del_produttore'>
				  <input type=submit title=cerca value=\"ELIMINA PRODUTTORE\"></td></tr></form>
				  <form name=search action=product_new.php method=post enctype=\"multipart/form-data\">
				  <tr><td class=tbtit colspan=2>LOGO PRODUTTORI</td></tr>
				  <tr>
				   <td align=left>Seleziona il PRODUTTORE ";
		  $sql = "SELECT distinct produttore FROM articoli_new WHERE produttore!='' AND giardino=3 ORDER BY produttore ASC;";
		  $rs_menu = $conn->Execute($sql);
		  $content .= $rs_menu->GetMenu2("produttore","",false);
		  $rs_menu->Close();
		 $content .= "<input type='hidden' name='op' value='logo_produttore'>Inserisci il logo(formato jpg,gif,png) 
		 		  <input type=file name=logo size=30>
				  <input type=submit title=cerca value=\"CARICA LOGO PRODUTTORE\"></td></tr></form>
				  <form name=search action=product_new.php method=post>
				  <tr>
				   <td align=left>Seleziona il PRODUTTORE ";
		  $sql = "SELECT distinct produttore FROM articoli_new WHERE produttore!='' AND giardino=3 ORDER BY produttore ASC;";
		  $rs_menu = $conn->Execute($sql);
		  $content .= $rs_menu->GetMenu2("produttore","",false);
		  $rs_menu->Close();
		 $content .= "<input type='hidden' name='op' value='del_logo_produttore'>
		 		  <input type=submit value=\"ELIMINA LOGO PRODUTTORE\"></td></tr>
				  </form>
				  </table>";
				break;
				
			case "getFornitore":
				$id = $_POST['id'];
				$qry = "SELECT id,fornitore FROM fornitore WHERE id=$id;";
				$rs = $conn->Execute($qry);
				die('{"fornitore":"'.utf8_encode($rs->Fields("fornitore")).'"}');
				break;
				
			case "updFornitore":
					$id = $_POST['id'];
					$fornitore = utf8_decode($_POST['fornitore']);
					$conn->Execute("UPDATE fornitore SET fornitore='$fornitore' WHERE id=$id;");
					die('{"success":true}');
				break;
				
			case "delFornitore":
				$id = $_POST['id'];
				$conn->Execute("DELETE FROM fornitore WHERE id=$id;");
				die('{"success":true}');
				break;
				
			case "salvaFornitore":
				$fornitore = utf8_decode($_POST['fornitore']);
				$conn->Execute("INSERT INTO fornitore VALUES(NULL,'$fornitore',0);");
				die('{"success":true}');
				break;
				
			case "del_produttore":
				$produttore = $_POST['produttore'];
				$conn->Execute("UPDATE articoli_new SET produttore='' WHERE produttore='$produttore';");
				header("Location: product_new.php?op=anag_prod");
				die();
				break;
				
			case "logo_produttore":
				$produttore = $_POST['produttore'];
				$logo = $_FILES['logo'];
				if($logo['name']!="") {
				  $ext = strtolower(substr($logo['name'],-3));
				  $file = $produttore.".".$ext;
				  move_uploaded_file($logo['tmp_name'],$path_image."/brends/".$file) ? $error = "Logo inserito correttamente" : "Problemi nell'inserimento del logo";
				} else {
					$error = "Devi inserire un file.";
				}
				$content = printError($error);
				break;
				
			case "del_logo_produttore":
				$produttore = $_POST['produttore'];
				if(file_exists($path_image."brends/".$produttore.".jpg")) unlink($path_image."brends/".$produttore.".jpg");
				if(file_exists($path_image."brends/".$produttore.".gif")) unlink($path_image."brends/".$produttore.".gif");
				if(file_exists($path_image."brends/".$produttore.".png")) unlink($path_image."brends/".$produttore.".png");
				$content = printError("Logo eliminato con successo!");
				break;
				
			case "move":
				$idarticolo = $_POST['idarticolo'];
				$cid = $_POST['cid'];
				$origine = $_POST['origine'];
				category::move($idarticolo,$cid,1);
				header("Location: product_new.php?cid=$origine&op=product");
				die();
				break;
				
			# CODICI #
				case "getCodice":
					$idarticolo = $_POST['idarticolo'];
				    $idfornitore = $_POST['idfornitore'];
					$qry = "SELECT * FROM articoli_fornitore WHERE idarticolo=$idarticolo AND idfornitore=$idfornitore;";
					die(get_json($qry));
					break;
				
				case "updCodice":
					$idarticolo = $_POST['idarticolo'];
					$idfornitore = $_POST['idfornitore'];
					$idfornitore_old = $_POST['idfornitore_old'];
					$costo = $_POST['costo'];
					$codice = $_POST['codice'];
					$conn->Execute("UPDATE articoli_fornitore SET idfornitore=$idfornitore,costo=$costo,codice='$codice' 
					WHERE idarticolo=$idarticolo AND idfornitore=$idfornitore_old;");
					die('{"success":true}');
					break;
				
				case "delCodice":
					$idarticolo = $_POST['idarticolo'];
					$idfornitore = $_POST['idfornitore'];
					$conn->Execute("DELETE FROM articoli_fornitore WHERE idarticolo=$idarticolo AND idfornitore=$idfornitore;");
					die('{"success":true}');
					break;
					
				case "setPrincipale":
						$idarticolo = $_POST['idarticolo'];
						$idfornitore = $_POST['idfornitore'];
						$conn->Execute("UPDATE articoli_fornitore SET principale=0 
					WHERE idarticolo=$idarticolo;");
						$conn->Execute("UPDATE articoli_fornitore SET principale=1 
						WHERE idarticolo=$idarticolo AND idfornitore=$idfornitore;");
						die('{"success":true}');
				break;
				
				case "salvaCodice":
					$idarticolo = $_POST['idarticolo'];
					$idfornitore = $_POST['idfornitore'];
					$fornitore_add = $_POST['fornitore_add'];
					if($fornitore_add!="") {
						$conn->Execute("INSERT INTO fornitore VALUES(NULL,'".utf8_decode($fornitore_add)."',3)");
						$idfornitore = $conn->Insert_ID();
					}
					$costo = $_POST['costo'];
					$codice = $_POST['codice'];
					$conn->Execute("INSERT INTO articoli_fornitore VALUES($idarticolo,$idfornitore,$costo,'$codice',0);");
					die('{"success":true}');
					break;
########################### VARIANTI ARTICOLO ##############################################################
			case "getVarianteArticolo":
				$id = $_POST['id'];
				$qry = "SELECT * FROM varianti WHERE id=$id;";
				die(get_json($qry));
				break;
					
			case "updVarianteArticolo":
				$id = $_POST['id_var'];
				$nome = $_POST['nome_var_mod'];
				$codice = $_POST['codice_var_mod'];
				$desc = $_POST['descrizione_var_mod'];
				$image = $_FILES['image_var_mod'];
				$idarticolo = $_POST['idarticolo_var'];
				$cid = $_POST['cid_var'];
				if($image['name']!="") {
					move_uploaded_file($image['tmp_name'], $_SERVER[DOCUMENT_ROOT]."/immagini-giardino/varianti/".$image['name']);
					$obj = new Image($_SERVER[DOCUMENT_ROOT]."/immagini-giardino/varianti/".$image['name']);
					if($obj->src_width > 600)
					$obj->SaveProportionateImage2($_SERVER['DOCUMENT_ROOT']."/immagini-giardino/varianti/".$image['name'], 80,0,600);
					else
					$obj->SaveProportionateImage2($_SERVER['DOCUMENT_ROOT']."/immagini-giardino/varianti/".$image['name'], 80,0,$obj->src_width);
					$img_name = ",image='".$image['name']."'";
				}
				$conn->Execute("UPDATE varianti SET nome='$nome',codice='$codice',descrizione='$desc' $img_name WHERE id=$id");
				header("Location:product_new.php?cid=$cid&op=product&idarticolo=$idarticolo");
				die();
				break;
				
			case "delVarianteArticolo":
				$id = $_POST['id'];
				$qry = "DELETE FROM varianti WHERE id=$id;";
				$conn->Execute($qry);
				die('{"success":true}');
				break;
				
			case "addVarianteArticolo":
				$id = $_POST['id_var'];
				$nome = $_POST['nome_var_add'];
				$codice = $_POST['codice_var_add'];
				$desc = $_POST['descrizione_var_add'];
				$image = $_FILES['image_var_add'];
				$idarticolo = $_POST['idarticolo_var'];
				$cid = $_POST['cid_var'];
				if($image['name']!="") {
					move_uploaded_file($image['tmp_name'], $_SERVER[DOCUMENT_ROOT]."/immagini-giardino/varianti/".$image['name']);
					$obj = new Image($_SERVER[DOCUMENT_ROOT]."/immagini-giardino/varianti/".$image['name']);
					if($obj->src_width > 600)
					$obj->SaveProportionateImage2($_SERVER['DOCUMENT_ROOT']."/immagini-giardino/varianti/".$image['name'], 80,0,600);
					else
					$obj->SaveProportionateImage2($_SERVER['DOCUMENT_ROOT']."/immagini-giardino/varianti/".$image['name'], 80,0,$obj->src_width);
					$img_name = $image['name'];
				}
				$conn->Execute("INSERT INTO varianti VALUES(NULL,$idarticolo,'$nome','$codice','$desc','$img_name');");
				header("Location:product_new.php?cid=$cid&op=product&idarticolo=$idarticolo");
				die();
				break;
###########################################################################################################				
			default:
				$content = "<table width=600 class=content cellpadding=3><form name=search action=product_new.php method=post><tr><td class=tbtit colspan=2>RICERCA ARTICOLO</td></tr>
				  <tr>
				   <td class=content align=right width=300>Cerca per codice / nome / descrizione / Fornitore:</td><td><input type=text size=60 name=search></td>
				  </tr>
				  <tr>
				   <td colspan=2 align=center>
				   <input type='hidden' name='op' value='search'>
				  <input type=submit title=cerca value=CERCA></td></tr></form></table>";			
				break;
		}
		//$menusx .= "</table>";
		$conn->Close();
		?>
<html>
<head>
<title>Modulo Prodotti</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style/style.css" rel="stylesheet" type="text/css">
<link type="text/css" href="js/theme/ui.all.css" rel="Stylesheet" />
<link rel="stylesheet" type="text/css" media="all" href="skins/aqua/theme.css" title="Aqua">
<script type="text/javascript" src="calendar.js"></script>
<script type="text/javascript" src="calendar-it.js"></script>
<script language="javascript">

var oldLink = null;
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}

// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
    cal.callCloseHandler();
}

function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}

function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
    // we already have some calendar created
    _dynarch_popupCalendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(1, null, selected, closeHandler);
    // uncomment the following line to hide the week numbers
    // cal.weekNumbers = false;
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    _dynarch_popupCalendar = cal;                  // remember it in the global var
    cal.setRange(1900, 2070);        // min/max year allowed.
    cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
  _dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
  _dynarch_popupCalendar.sel = el;                 // inform it what input field we use

  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  return false;
}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;

function isDisabled(date) {
  var today = new Date();
  return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
}

function flatSelected(cal, date) {
  var el = document.getElementById("preview");
  el.innerHTML = date;
}

function showFlatCalendar() {
  var parent = document.getElementById("display");

  var cal = new Calendar(0, null, flatSelected);

  cal.weekNumbers = false;

  cal.setDisabledHandler(isDisabled);
  cal.setDateFormat("%A, %B %e");

  cal.create(parent);

  cal.show();
}
</script>
<script language="javascript">

function check_date(field){

var checkstr = "0123456789";

var DateField = field;

var Datevalue = "";

var DateTemp = "";

var seperator = "/";

var day;

var month;

var year;

var step = 0;

var err = 0;

var i;

   err = 0;

   DateValue = DateField.value;

   /* cancello tutti i dati tranne 0-9 */

   for (i = 0; i < DateValue.length; i++) {

              if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {

                 DateTemp = DateTemp + DateValue.substr(i,1);

              }

   }

   DateValue = DateTemp;

  /* se l'anno � inserito con 2 valori lo cambio sempre con  20xx */

   if (DateValue.length == 6) {

      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }

   if (DateValue.length != 8) {

      err = 19;}

   /* anno sbagliato 0000 */

   year = DateValue.substr(4,4);

   if (year == 0) {

      err = 20;

   }

   /* validazione del mese*/

   month = DateValue.substr(2,2);

   if ((month < 1) || (month > 12)) {

      err = 21;

   }

   /* validazione del giorno */

   day = DateValue.substr(0,2);

   if (day < 1) {

     err = 22;

   }

   /* Validazione anno / febbraio / gg */

   if ((year % 4 == 0)) {

      step = 1;

   }

   if ((month == 2) && (step == 1) && (day > 29)) {

      err = 23;

   }

   if ((month == 2) && (step != 1) && (day > 28)) {

      err = 24;

   }

   /* validazione dei mesi */

   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {

      err = 25;

   }

   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {

      err = 26;

   }

   /* se � inserito 00 cancello i dati */

   if ((day == 0) && (month == 0) && (year == 00)) {

      err = 0; day = ""; month = ""; year = ""; seperator = "";

   }

   /* Se non ci sono errori inserisco la data (esempio 13.12.2001) */

   if (err == 0) {

      DateField.value = day + seperator + month + seperator + year;

   }

   /* Messaggio di errore, avviso di data corretta se err diverso da 0 */

   else {

      alert("La data non e' corretta.\n\nIl formato consentito e':\n  gg/mm/aaaa\n  - gg/mm/aa\n");

      DateField.select();

              DateField.focus();

   }

}
</script>
<script language="javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-personalized-1.6rc6.js"></script>
<script language="javascript" src="js/ui.datepicker-it.js"></script>
<script language="javascript" src="js/functions.js"></script>
<script language="javascript" src="js/ajax.js"></script>
<script language="javascript">

function showHide(id, idsezione, nome)  {
	var obj;
	obj=MM_findObj(id);
	if(obj.style.visibility=='visible')
	 MM_showHideLayers(id,'','hide');
	else  {
	 MM_showHideLayers(id,'','show');
	 //document.addservice.currentpage.value=location.href;
	 //document.modtopic.page.value=location.href;	
	 if(id == "addservizio")  {
	  if(idsezione != "")  {
		  document.addservice.nome.value=nome;
		  document.addservice.idservizio.value=idsezione;
		  document.addservice.op.value="update";
		  document.addservice.nome.focus();
	  } else {
		  document.addservice.op.value="save";
		  document.addservice.nome.focus();	  
	  }
	 }
	 if(id == "editServizio") {
	   document.modservizio.nomeupd.value = nome;
	   document.modservizio.idservizioupd.value = idsezione;
	 }
	}
}

</script>
<link href="style/style.css" rel="stylesheet" type="text/css">
<script type="text/JavaScript">
<!--
<?=$javascript?>

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  var dis;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) {
	   obj=obj.style; 
	   if(v == 'show')  {
	     v = 'visible';
		 dis = 'block';
	   }
	   if(v == 'hide')  {
	     v = 'hidden';
		 dis = 'none';	 
	   }
	 }  
    obj.visibility = v; 
	obj.display = dis;
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

$(document).ready(function(){
	  $('body').append('<div id="mod_attr"></div><div id="list_val_attr"></div>');
	  $("#dialog_buono").dialog({
	        bgiframe: true,
	        modal: true,
	        width: 400,
			autoOpen: false,
	        title: 'Modifica Codice',
	        close: function(event, ui){
	            //$(this).html('');
	            //$(this).dialog('destroy');
	        },
	        buttons: {
	            'Salva': function(){
	                $.ajax({
	                    type: 'POST',
	                    url: 'product_new.php',
	                    data: '&op=updbuono' +
	                    '&codice=' +
	                    $('#codice_edit').val() +
						'&start='+$('#start_edit').val()+
						'&end='+$('#end_edit').val()+
	                    '&valore=' +
	                    $('#valore_edit').val() +
	                    '&percentuale=' +
	                    $('#percentuale_edit').val() +
	                    '&minimo=' +
	                    $('#minimo_edit').val() +
	                    '&idbuono=' +
	                    $('#idbuono_edit').val(),
	                    dataType: 'html',
	                    async: false,
	                    success: function(msg){
	                	location.reload();
	                        //$('#grid_buoni').html(msg);
	                    }
	                });
	            },
	            'Annulla': function(){
	                $(this).dialog('close');
	            }
	        }
	    });
	  $("#dialog_addbuono").dialog({
	        bgiframe: true,
	        modal: true,
	        width: 400,
			autoOpen: false,
	        title: 'Nuovo Codice',
	        close: function(event, ui){
	            //$(this).html('');
	            //$(this).dialog('destroy');
	        },
	        buttons: {
	            'Salva': function(){
	                $.ajax({
	                    type: 'POST',
	                    url: 'product_new.php',
	                    data: '&op=addbuono' +
	                    '&codice=' +
						$('#codice').val() +
						'&start='+$('#start').val()+
						'&end='+$('#end').val()+
	                    '&valore=' +
	                    $('#valore').val() +
	                    '&percentuale=' +
	                    $('#percentuale').val() +
	                    '&minimo=' +
	                    $('#minimo').val(),
	                    dataType: 'html',
	                    success: function(msg){
							location.reload();
                        	//$('#grid_buoni').html(msg);
	                    }
	                });
	            },
	            'Annulla': function(){
	                $(this).dialog('close');
	            }
	        }
	    });
	});
//-->
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0"
	marginheight="0"
	onLoad="MM_preloadImages('imgs/icons/pag_web-b.gif','imgs/icons/info_utente-b.gif','imgs/icons/prodotti-b.gif','imgs/icons/newsletter-b.gif','imgs/icons/news-b.gif','imgs/icons/gest_banner-b.gif','imgs/icons/utenti-b.gif','imgs/icons/configurazione-b.gif','imgs/icons/kw-b.gif'); <?=$onload?>">
<!-- ImageReady Slices (gestione.psd - Slices: 02, 03, 04, 06, 07, 08, 09, 10, 11, 12) -->
<!-- End ImageReady Slices -->
<table width="100%" height="100%" border="0" cellpadding="0"
	cellspacing="0">
	<tr>
		<td width="40" height="177" background="imgs/bkgSx.gif">&nbsp;</td>
		<td>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="552" background="imgs/gestione_02.gif">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="360"><img src="imgs/spacer20.gif" width="360"
							height="73"></td>
						<td>
						<table width="100%" height="73" border="0" cellpadding="0"
							cellspacing="0">
							<tr>
								<td height="5"><img src="imgs/spacer20.gif" width="45"
									height="5"></td>
							</tr>
							<tr>
								<td align="left" valign="middle" class="tit01"><!-- InstanceBeginEditable name="user" --><?=$username?><!-- InstanceEndEditable --></td>
							</tr>
						</table>
						</td>
					</tr>
				</table>
				</td>
				<td background="imgs/gestione_03.gif">&nbsp;</td>
				<td width="221">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td><img src="imgs/gestione_04.gif" width="221" height="17" alt=""></td>
					</tr>
					<tr>
						<td>
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="57"><a href="gestione.php?logout=1"><img
									src="imgs/gestione_06.gif" alt="Logout" width="57" height="51"
									border="0"></a></td>
								<td>
								<table width="100%" border="0" cellspacing="0" cellpadding="0">
									<tr>
										<td><a href="mailto:info@media-tek.it"><img
											src="imgs/gestione_07.gif" alt="" width="164" height="25"
											border="0"></a></td>
									</tr>
									<tr>
										<td><a href="#"><img src="imgs/gestione_08.gif" alt=""
											width="164" height="26" border="0"></a></td>
									</tr>
								</table>
								</td>
							</tr>
						</table>
						</td>
					</tr>
					<tr>
						<td><img src="imgs/gestione_09.gif" width="221" height="5" alt=""></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		<table width="100%" height="104" border="0" cellpadding="0"
			cellspacing="0">
			<tr>
				<td width="678" background="imgs/gestione_10.gif">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="203">
						<table width="203" height="104" border="0" cellpadding="0"
							cellspacing="0">
							<tr>
								<td><img src="imgs/spacer20.gif" width="203" height="65"></td>
							</tr>
							<tr>
								<td>
								<table width="100%" border="0" cellspacing="0" cellpadding="0">
									<tr>
										<td width="45"><img src="imgs/spacer20.gif" width="45"
											height="39"></td>
										<td>
										<table width="100%" height="39" border="0" cellpadding="5"
											cellspacing="0">
											<tr>
												<td align="left" valign="middle" class="module"><?=$module?>
												</td>
											</tr>
										</table>
										</td>
									</tr>
								</table>
								</td>
							</tr>
						</table>
						</td>
						<td>
						<table width="475" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="50"><img src="imgs/spacer20.gif" width="50"
									height="104" alt=""></td>
								<td align="left" valign="bottom"><? if($level!="VBL")  { ?>
								<table border="0" cellspacing="0" cellpadding="2">
									<tr>
									<?
									if($level=="admin")  {
										?>
										<td width="58"><a href="gestione.php?module=content"
											onMouseOut="MM_swapImgRestore()"
											onMouseOver="MM_swapImage('pages','','imgs/icons/pag_web-b.gif',1)"><img
											src="imgs/icons/pag_web.gif" alt="Pagine web" name="pages"
											width="58" height="69" border="0"></a></td>
										<td width="58"><a href="gestione.php?module=newsletter"
											onMouseOut="MM_swapImgRestore()"
											onMouseOver="MM_swapImage('Newsletter','','imgs/icons/newsletter-b.gif',1)"><img
											src="imgs/icons/newsletter.gif" alt="Newsletter"
											name="Newsletter" width="58" height="69" border="0"></a></td>
											<?
									}
									?>
										<td width="58"><a href="gestione.php?module=banner"
											onMouseOut="MM_swapImgRestore()"
											onMouseOver="MM_swapImage('banner','','imgs/icons/gest_banner-b.gif',1)"><img
											src="imgs/icons/gest_banner.gif" alt="Gestione Banner"
											name="banner" width="58" height="69" border="0"></a></td>
										<td width="58"><a href="gestione.php?module=prodotti"><img
											src="imgs/icons/prodotti.gif" alt="Pagine Web" name="pagine"
											width="58" height="69" border="0" id="pagine"
											onMouseOver="MM_swapImage('pagine','','imgs/icons/prodotti-b.gif',1)"
											onMouseOut="MM_swapImgRestore()"></a></td>
									</tr>
								</table>
								<? } ?></td>
							</tr>
						</table>
						</td>
					</tr>
				</table>
				</td>
				<td valign="bottom" background="imgs/gestione_11.gif">
				<table cellpadding="2" cellspacing="0">
					<tr>
						<td width="58"><a href="gestione.php?module=webuser"
							onMouseOut="MM_swapImgRestore()"
							onMouseOver="MM_swapImage('webutente','','imgs/icons/utenti-b.gif',1)"><img
							src="imgs/icons/utenti.gif" name="webutente" width="58"
							height="69" border="0"></a></td>
							<?
				if($level=="admin")  {
					?>
						<td width="58"><a href="gestione.php?module=user"
							onMouseOut="MM_swapImgRestore()"
							onMouseOver="MM_swapImage('Utente','','imgs/icons/info_utente-b.gif',1)"><img
							src="imgs/icons/info_utente.gif" name="Utente" width="58"
							height="69" border="0"></a></td>
						
				<?
				} else {
					?>&nbsp;<?
				}
				?>
						<td width="20" valign="middle">
						</td>
					</tr>
				</table>
				</td>
				<td width="95"><img src="imgs/gestione_12.gif" width="95"
					height="104" alt=""></td>
			</tr>
		</table>
		</td>
		<td width="40" background="imgs/bkgDx.gif">&nbsp;</td>
	</tr>
	<tr>
		<td background="imgs/bkgSx.gif">&nbsp;</td>
		<td valign="top" bgcolor="#F6F6F6">
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td width="203" align="left" valign="top" bgcolor="#DFDFDF"
					class="menusx"><!-- InstanceBeginEditable name="menuSx" --><?=$menusx?>
				<table width="100%" class="menusx" cellpadding="2"
					id="addcategoria2">
					<form name=formaddcat action=product_new.php method=post>
					<tr>
						<td>Titolo:</td>
						<td><input type=text size=30 name=titolo></td>
					</tr>
					<tr>
						<td colspan="2">Descrizione categoria:<br>
						<textarea name="desc" cols="40" rows="10"></textarea></td>
					</tr>
					<tr>
						<td><input type='hidden' name='op' value="save"> <input
							type="hidden" name="currentpage" value="<?=$currentpage?>"> <input
							type=image src="imgs/ico_save.gif" title=Salva
							onClick="return control_addcat();" width=16 height=16></td>
						<td><a href="#" onClick="showHide('addcategoria2');"><img
							src="imgs/ico_delete.gif" width="16" height="16" border=0
							alt="Chiudi"></a></td>
					</tr>
					</form>
				</table>
				<table class=menusx width=100% border=0>
					<tr>
						<td valign=middle width=30 height=30><a class=menusx
							href="product_new.php?op=import"><img src="imgs/ico_list.gif"
							width=30 height=30 alt="Importa Articoli" border=0></a></td>
						<td align=left valign=middle><a class=menusx
							href="product_new.php?op=import">Importa Articoli</a></td>
					</tr>
					<tr>
						<td valign=middle width=30 height=30><a class=menusx
							href="product_new.php?op=import_ordine_minimo"><img
							src="imgs/ico_list.gif" width=30 height=30 alt="Importa Articoli"
							border=0></a></td>
						<td align=left valign=middle><a class=menusx
							href="product_new.php?op=import_ordine_minimo">Importa Ordine
						Minimo</a></td>
					</tr>
					<tr>
						<td valign=middle width=30 height=30><a class=menusx
							href="product_new.php?op=get_csv&cid=<?=$cids?>&percorso=<?=$percorso?>"><img
							src="imgs/ico_list.gif" width=30 height=30 alt="Esporta Articoli"
							border=0></a></td>
						<td align=left valign=middle><a class=menusx
							href="product_new.php?op=get_csv&cid=<?=$cids?>&percorso=<?=$percorso?>">Esporta
						Articoli</a></td>
					</tr>
					<tr>
						<td valign=middle width=30 height=30><a class=menusx
							href="product_new.php?op=promozioni&cid=733"><img
							src="imgs/ico_list.gif" width=30 height=30
							alt="Promozioni Piscine" border=0></a></td>
						<td align=left valign=middle><a class=menusx
							href="product_new.php?op=promozioni&cid=733">Gestione Promozioni
						Piscine</a></td>
					</tr>
					<tr>
						<td valign=middle width=30 height=30><a class=menusx
							href="product_new.php?op=get_buoni"><img src="imgs/ico_list.gif"
							width=30 height=30 alt="Buoni Sconto" border=0></a></td>
						<td align=left valign=middle><a class=menusx
							href="product_new.php?op=get_buoni">Gestione Buoni Sconto</a></td>
					</tr>
					<tr>
						<td valign=middle width=30 height=30><a class=menusx
							href="product_new.php?op=scontistica"><img src="imgs/ico_list.gif"
							width=30 height=30 alt="Gestione Scontistica" border=0></a></td>
						<td align=left valign=middle><a class=menusx
							href="product_new.php?op=scontistica">Gestione Scontistica</a></td>
					</tr>
					<tr>
						<td valign=middle width=30 height=30><a class=menusx
							href=gestione.php><img src="imgs/ico_back.gif" width=30 height=30
							alt=Principale border=0></a></td>
						<td align=left valign=middle><a class=menusx href=gestione.php>Torna
						alla pagina principale</a></td>
					</tr>
				</table>
				</td>
				<td align="left" valign="top" bgcolor="#EFEFEF" class="content"><!-- InstanceBeginEditable name="content" --><?=$content?>
				</td>
			</tr>
		</table>
		<table width="100%" height="50" border="0" cellpadding="5"
			cellspacing="0">
			<tr>
				<td background="imgs/gestione_03.gif" bgcolor="#F6F6F6" class="copy">
				<p>2006&copy; Gestione moduli dinamici - release 1.2 - Powered by
				Media-tek</p>
				</td>
			</tr>
		</table>
		</td>
		<td background="imgs/bkgDx.gif">&nbsp;</td>
	</tr>
</table>
<div id="mod_attributo" style="display: none;">
<label>Attributo:</label><input
	type="text" id="nome_attr_edit" name="nome_attr_edit">
</div>
</body>
</html>
				<?
				break;

case AUTH_NOT_LOGGED:
	header("Location:index.html");
	break;
}
?>